PARABOLIC SAR

Back to topics list To post a new topic, please log in or register
avatar
9
sky6nove 2015.01.08 13:21
 
I would use "PARABOLIC SAR" AS AND THE indicator.
EX. as the last ball of low or high as support and resistance.

which parameter should I use to get the last ball of the trend that is closed as a reference?
avatar
Moderator
3418
GumRai 2015.01.08 13:31 #
 

I think that you are probably using some translation software and it doesn't work.

Your post is just nonsense! 

avatar
2017
gooly 2015.01.08 14:23 #
 

For your EA look in the reference for iSAR, google for "mt4 iSAR" you'll find examples of how to code/use it.

If you are new, make it your habit google or search here for keywords or read the Book or Documentation (Links at the Top)

avatar
9
sky6nove 2015.01.09 20:39 #
 
GumRai:

I think that you are probably using some translation software and it doesn't work.

Your post is just nonsense! 

ok 

 

thanks for replying. I would like to get help because already researched enough but did not think about this example code.

could direct me to an example that you've seen already?


I want to get the last ball of the parabolic sar reference.


follows in the image and the code I'm trying to modify the example. 

 

 

 

 

 

 

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
extern double TakeProfit=1000;
extern double timeframe=0; //0=atual / 1=1M / 60=1H / 240=4H / 1440=1D / 10080=1Semana / 43200=1MES
extern double Lots=0.10;
extern double PTrend=1440;
extern double TrailingStop=300;
extern double Stop_loss_buy=0;
extern double Stop_loss_sell=0;


//---
string lastSignalUsed="No signal";
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   
   double Price1,Price2,LastSar;
   int cnt,ticket,total;
   
   
   LastSar=iSAR(NULL,0,.005,0.02,0); // Problem lastSignal 
   
   Price1=iMA(NULL,timeframe,1,0,MODE_SMA,0,1);         //PREÇO atual
   Price2=iMA(NULL,timeframe,1,0,MODE_SMA,0,2);         //PREÇO anterior
 
 
 
    total=OrdersTotal();
   if(total<1)
     {

      if(AccountFreeMargin()<(1*Lots))
        {
         Print("Account Free Margin = ",AccountFreeMargin());
         return(0);
        }

      if(    
             Price1>LastSar && lastSignalUsed!="Buy"
              
     
      
      
      
      
      )
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Stop_loss_buy,Ask+TakeProfit*Point,"EA SKY TRADE",123456,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
               {
               Print("BUY : ",OrderOpenPrice());
               lastSignalUsed="Buy";
               }
           }
         else Print("BUY Error: ",GetLastError());
         return(0);
        }

      if(            
                      Price1<LastSar && lastSignalUsed!="Sell"
                      
      
      
      
      )
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Stop_loss_sell,Bid-TakeProfit*Point,"EA SKY TRADE",123456,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
               {
               Print("SELL : ",OrderOpenPrice());
               lastSignalUsed="Sell";
               }
           }
         else Print("SELL  Error: ",GetLastError());
         return(0);
        }
      return(0);
     }

   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
        {
         Print("OrderSelect() failed with error :  "+GetLastError());
        }
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)
           {

            if(   //CLOSE BUY
            
                    
                   Price1<LastSar
                             
            ) 
              {
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Red))
                 {
                  Print("OrderClose() failed with error :  "+GetLastError());
                  return(0);
                 }
              }

            if(TrailingStop>0)
              {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Gray))
                       {
                        Print("OrderModify() failed with error :  "+GetLastError());
                       }
                     return(0);
                    }
                 }
              }
           }
         else
           {
            if(        //CLOSE SELL
            
            
                                 
                             Price1>LastSar 
                                        
            
            ) 
            
              {
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime))
                 {
                  Print("OrderClose() failed with error :  "+GetLastError());
                  return(0);
                 }
              }
            if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Gray))
                       {
                        Print("OrderModify() failed with error :  "+GetLastError());
                        return(0);
                         }
                       }
                    }
                 }
              }
           }
         }
   return(0);
  }
//+------------------------------------------------------------------+

 

avatar
2017
gooly 2015.01.09 21:41 #
 
(untested) If iSar  'switches' from Sell to Buy => iSar(..0) < Low[0] & iSAR(..1) > High[1] => save Sar(..,1) as entry for the next Buy - if it is this what you mean
avatar
Moderator
3418
GumRai 2015.01.09 23:32 #
 

You can use and adapt this to find the values that you want

  string comment_string="";
  int x=1;
  double last_upper_SAR, last_lower_SAR,SAR_value;
  static datetime LastBar=0;
  if(Time[0]!=LastBar)
     {
     LastBar=Time[0];
     SAR_value=iSAR(NULL,0,0.02,0.2,1);
     if(SAR_value>Close[1])                     //Last closed SAR was above price
        {
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,0.02,0.2,x);
           if(SAR_value<Close[x])
              {
              last_lower_SAR=SAR_value;
              comment_string+="Last Lower SAR = "+DoubleToStr(last_lower_SAR,Digits)+", Bar Time "
                              +TimeToStr(Time[x],TIME_DATE|TIME_MINUTES)+"\n";
              break;
              }
           }
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,0.02,0.2,x);
           if(SAR_value>Close[x])
              {
              last_upper_SAR=SAR_value;
              comment_string+="Last Upper SAR = "+DoubleToStr(last_upper_SAR,Digits)+", Bar Time "
                              +TimeToStr(Time[x],TIME_DATE|TIME_MINUTES);
              break;
              }
           }
        }
     else                     //Last closed SAR was below price
        {
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,0.02,0.2,x);
           if(SAR_value>Close[x])
              {
              last_upper_SAR=SAR_value;
              comment_string+="Last Upper SAR = "+DoubleToStr(last_upper_SAR,Digits)+", Bar Time "
                              +TimeToStr(Time[x],TIME_DATE|TIME_MINUTES)+"\n";
              break;
              }
           }
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,0.02,0.2,x);
           if(SAR_value<Close[x])
              {
              last_lower_SAR=SAR_value;
              comment_string+="Last Lower SAR = "+DoubleToStr(last_lower_SAR,Digits)+", Bar Time "
                              +TimeToStr(Time[x],TIME_DATE|TIME_MINUTES);
              break;
              }
           }
        }
     Comment(comment_string);
     }
   

 

avatar
Moderator
3418
GumRai 2015.01.11 13:24 #
 

Don't code a separate indicator, use the code directly in your EA.

With these lines in your EA

   last_upper_SAR=iCustom(NULL,0,"SKY_SAR_INDICADOR",0,0.007,0.02,0);
   last_lower_SAR=iCustom(NULL,0,"SKY_SAR_INDICADOR",0,0.007,0.02,0);

 You are trying to access buffers that do not exist

avatar
Moderator
3418
GumRai 2015.01.11 21:54 #
 

I will look at your code later, but note with this

   closeprice1 = (iClose("NULL",0,1));
   closeprice2 = (iClose("NULL",0,2));
   
   Price1=iMA(NULL,timeframe,1,0,0,0,1);         //PREÇO atual
   Price2=iMA(NULL,timeframe,1,0,0,0,2);         //PREÇO anterior

 There should not be quotation marks around NULL

Also, as the period for iMA is set to 1, when timeframe is the same as current

closeprice1 returns the same as Price1 

and

closeprice2 returns the same as Price2 

Why the need to use an MA, just use iClose

EDIT:Badly worded 

avatar
Moderator
3418
GumRai 2015.01.12 08:54 #
 

Not tested.

I've made some adjustments to your code that should get you started on the right track

I haven't looked at the last section of code that I have commented out

extern double TakeProfit=1000;
extern int    timeframe=0; //0=atual / 1=1M / 60=1H / 240=4H / 1440=1D / 10080=1Semana / 43200=1MES
extern double Lots=0.10;
extern double PTrend=1440;
extern double TrailingStop=300;
extern double Stop_loss_buy=0;
extern double Stop_loss_sell=0;
extern double Step=0.007;
extern double Maximum=0.02;

double last_upper_SAR,last_lower_SAR;
string lastSignalUsed="No signal";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
  double SAR_value,Price1,Price2,closeprice1,closeprice2;
  int cnt,ticket,total;
   
  int x=1;
  static datetime LastBar=0;
  if(Time[0]!=LastBar)
     {
     LastBar=Time[0];
     SAR_value=iSAR(NULL,0,Step,Maximum,1);
     if(SAR_value>Close[1])                     //Last closed SAR was above price
        {
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,Step,Maximum,x);
           if(SAR_value<Close[x])
              {
              last_lower_SAR=SAR_value;
              break;
              }
           }
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,Step,Maximum,x);
           if(SAR_value>Close[x])
              {
              last_upper_SAR=SAR_value;
              break;
              }
           }
        }
     else                     //Last closed SAR was below price
        {
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,Step,Maximum,x);
           if(SAR_value>Close[x])
              {
              last_upper_SAR=SAR_value;
              break;
              }
           }
        while(true)
           {
           x++;
           SAR_value=iSAR(NULL,0,Step,Maximum,x);
           if(SAR_value<Close[x])
              {
              last_lower_SAR=SAR_value;
              break;
              }
           }
        }
     }
   
   closeprice1 = (iClose(NULL,0,1));
   closeprice2 = (iClose(NULL,0,2));
   
   Price1=iMA(NULL,timeframe,1,0,0,0,1);         //PREÇO atual
   Price2=iMA(NULL,timeframe,1,0,0,0,2);         //PREÇO anterior
 
   total=OrdersTotal();
   if(total<1)
     {
      if(AccountFreeMargin()<(1*Lots))
        {
         Print("Account Free Margin = ",AccountFreeMargin());
         return(0);
        }

      if(Price1>last_upper_SAR && Price2<last_upper_SAR && lastSignalUsed!="Buy")
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Stop_loss_buy,Ask+TakeProfit*Point,"EA SKY TRADE",123456,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
               {
               Print("BUY : ",OrderOpenPrice());
               lastSignalUsed="Buy";
               }
           }
         else Print("BUY Error: ",GetLastError());
         return(0);
        }

      if(Price1<last_lower_SAR && Price2>last_lower_SAR && lastSignalUsed!="Sell")
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Stop_loss_sell,Bid-TakeProfit*Point,"EA SKY TRADE",123456,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
               {
               Print("SELL : ",OrderOpenPrice());
               lastSignalUsed="Sell";
               }
           }
         else Print("SELL  Error: ",GetLastError());
         return(0);
        }
      return(0);
     }
/*
   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
        {
         Print("OrderSelect() failed with error :  "+(string)GetLastError());
        }
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)
           {

            if(   //CLOSE BUY
            
                    
                     Price1<last_upper_SAR && Price2>last_upper_SAR
                      
                      
                             
            ) 
              {
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Red))
                 {
                  Print("OrderClose() failed with error :  "+(string)GetLastError());
                  return(0);
                 }
              }

            if(TrailingStop>0)
              {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Gray))
                       {
                        Print("OrderModify() failed with error :  "+(string)GetLastError());
                       }
                     return(0);
                    }
                 }
              }
           }
         else
           {
            if(        //CLOSE SELL
            
            
                                 
                             Price1>last_lower_SAR && Price2<last_lower_SAR 
             
            
            ) 
            
              {
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Lime))
                 {
                  Print("OrderClose() failed with error :  "+(string)GetLastError());
                  return(0);
                 }
              }
            if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Gray))
                       {
                        Print("OrderModify() failed with error :  "+(string)GetLastError());
                        return(0);
                         }
                       }
                    }
                 }
              }
           }
         }
   */
   return(0);
  
   
  }
//+------------------------------------------------------------------+

 

 

avatar
9
sky6nove 2015.01.12 23:58 #
 
very good,

was very good.

sure you put me on the right track.

will be a great EA when finalizing the methods to enter and stop.


the output term will still be manual, the problem was to enter the trade because of not to stay awake 24 hours.

lost entry in the trade because he was asleep.

thanks for your help.
Back to topics list  

To add comments, please log in or register