[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 120

 

I want to write an Expert Advisor on the Pincer pattern.

I have chosen

Low2=Low[iLowest(NULL,0,MODE_LOW,10,2)]    
High2=High[iHighest(NULL,0,MODE_HIGH,10,2)]     

if(Low[1]==Low2) bull_pincet=true;
if(High[1]==High2) bear_pincet=true;

   while(true)
      {
       
       if(Total==0 && bull_pincet==true)
        {
         sl=Low[1];
         if(sl<Step)sl=Step;
         tp=Ask+((Ask-sl)*k);
                  
         OrderSend(Symb,OP_BUY,Lts,Ask,3,sl,tp);
         return;
        }

        if(Total==0 && bear_pincet==true)
         {
          sl=High[1];
          if(sl<Step)sl=Step;
          tp=Bid-((sl-Bid)*k);
          OrderSend(Symb,OP_SELL,Lts,Bid,3,sl,tp);
          return;
         }
       break;
      }   

Unfortunately for me the condition is wrong because 'sl' is set to 100.00000 and 'tp' is showing an error.

I decided to add a condition to consider 1 tick.

static datetime TimeSaveH1  = 0;
int init()
{
     TimeSaveH1  = iTime( Symbol(), Period(), 0); // берем открытия время текущего бара
}

int start()
{
         if (TimeSaveH1!=iTime( Symbol(), Period(), 0))
            {
               TimeSaveH1=iTime( Symbol(), Period(), 0); 
            }  

Low2=Low[iLowest(NULL,0,MODE_LOW,10,2)]    
High2=High[iHighest(NULL,0,MODE_HIGH,10,2)]     

if(Low[1]==Low2 && TimeSaveH1===iTime( Symbol(), Period(), 0) bull_pincet=true;
if(High[1]==High2 && TimeSaveH1===iTime( Symbol(), Period(), 0) bear_pincet=true;
   while(true)
      {
       
       if(Total==0 && bull_pincet==true)
        {
         sl=Low[1];
         if(sl<Step)sl=Step;
         tp=Ask+((Ask-sl)*k);
                  
         OrderSend(Symb,OP_BUY,Lts,Ask,3,sl,tp);
         return;
        }

        if(Total==0 && bear_pincet==true)
         {
          sl=High[1];
          if(sl<Step)sl=Step;
          tp=Bid-((sl-Bid)*k);
          OrderSend(Symb,OP_SELL,Lts,Bid,3,sl,tp);
          return;
         }
       break;
      }   




}

the result is the same. how do i solve my problem?

 
kilnart:

I want to write an Expert Advisor on the pincer pattern.

I have chosen

Unfortunately for me the condition is wrong because 'sl' is set to 100.00000 and 'tp' is showing an error.

I decided to add a condition to consider 1 tick.

The result is the same. How do I correctly solve my problem?

You have a variable Step=100 ? If so, see what you get further in the code.

 
      Step=MarketInfo(Symb,MODE_STOPLEVEL);
 
kilnart:

Look, semicolons (;),

  Low2=Low[iLowest(NULL,0,MODE_LOW,10,2)]    
  High2=High[iHighest(NULL,0,MODE_HIGH,10,2)] 
 
It's all there. I just didn't think much of it when I posted on the forum.
 
kilnart:
It's all there. I just didn't think much of it when I posted on the forum.
Here's your code, everything works.
//+------------------------------------------------------------------+
//|                                                     Проверка.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  bool bull_pincet=false;
  bool bear_pincet=false;
  double sl,tp;
  int Total=OrdersTotal(); 
  double Step=MarketInfo(Symbol(),MODE_STOPLEVEL);
//----
 double Low2=Low[iLowest(NULL,0,MODE_LOW,10,2)];    
 double High2=High[iHighest(NULL,0,MODE_HIGH,10,2)];     

if(Low[1]==Low2 ) bull_pincet=true;
if(High[1]==High2) bear_pincet=true;
   while(true)
      {
       
       if(Total==0 && bull_pincet==true)
        {
         sl=Low[1];
         if(sl<Step)sl=Step;
         tp=Ask+((Ask-sl)*2);
                  
         OrderSend(Symbol(),OP_BUY,0.01,Ask,3,sl,tp);
         return;
        }

        if(Total==0 && bear_pincet==true)
         {
          sl=High[1];
          if(sl<Step)sl=Step;
          tp=Bid-((sl-Bid)*2);
          OrderSend(Symbol(),OP_SELL,0.01,Bid,3,sl,tp);
          return;
         }
       break;
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
I copied and pasted the code, corrected some errors and the result is the same as mine. stop loss is at 100.00000
 
copied, pasted, corrected some errors, the result -- the code works in the tester at 4 digits:
int init() {return(0);}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){ return(0); }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  bool bull_pincet=false;
  bool bear_pincet=false;
  double sl,tp;
  int Total=OrdersTotal(); 
  double Step=MarketInfo(Symbol(),MODE_STOPLEVEL);
//----
double Low2=Low[iLowest(NULL,0,MODE_LOW,10,2)];    
double High2=High[iHighest(NULL,0,MODE_HIGH,10,2)];     

if(Low[1]==Low2 ) bull_pincet=true;
if(High[1]==High2) bear_pincet=true;
   while(true)
      {
       if(Total==0 && bull_pincet==true)
        {
         sl=Low[1];
         if(sl>Bid-Step*Point)sl=Bid-Step*Point;
        tp=Bid+Step*Point*2;
         
         //if(sl<Step)sl=Step;
        // tp=Ask+((Ask-sl)*2);
                  
         OrderSend(Symbol(),OP_BUY,0.1,Ask,3,sl,tp);
         return;
        }

        if(Total==0 && bear_pincet==true)
         {
          sl=High[1];
          if(sl<Ask+Step*Point)sl=Ask+Step*Point;
         tp=Ask-Step*Point*2;
        //  if(sl<Step)sl=Step;
         // tp=Bid-((sl-Bid)*2);
          OrderSend(Symbol(),OP_SELL,0.1,Bid,3,sl,tp);
          return;
         }
       break;
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
Fillelin:
Here I can offer you a similar SCRIPT.

Description in code.

Thank you! If it's a script, it might work - a script can work as an EA if you put it in experts.

As for the EA I have not managed to compile it, I have encountered some errors in the end:

'GetNameOP' - function is not defined C:\Program Files (x86)\IamFX MT4\experts\VirtTPSL-Tr_EA.mq4 (45, 31)
'ErrorDescription' - function is not defined C:\Program Files (x86)\IamFX MT4\experts\VirtTPSL-Tr_EA.mq4 (45, 49)
Even after corrections - 2 custom functions are missing.
 
Roll:
copied, pasted, corrected some errors, the result is that the code works in the tester at 4 digits:

All right, well done. Let's see if step=0

  if(sl>Bid-Step*Point)sl=Bid-Step*Point;
  tp=Bid+Step*Point*2;

what sl and tp will be equal to.

And the person who raised this question should set order sl=0, tp=0 and then modify it.

This must be it.

Reason: