And let's make a "cartoon" out of it (multicurrency) - page 6

 
Swan >> :

error 130 all the time.

StopLevel should be checked, for StopLoss and Enter.


and icho

should the highest one be chosen?


-130 probably because of an attempt to set a pending order, and the price went above or below) in the code, there are lines uncommented with Marketlevel... this is the future price tracking, so there is no this error)

-Lowest low or high of OrderOpenPrice for stop) If buy, lowest H4 low of 0 candle and 1 candle... and the highest high for a sell... Generally lowest low/high for stop

 
ALex2008 >> :

-130 probably because of an attempt to set a pending order, and the price went higher or lower) in the code there are lines uncommented with Marketlevel... this is the future price tracking, so that there is no this error).

-Lowest low or high of OrderOpenPrice for stop) If buy, choose the lowest H4 low of 0 candle and 1 candle... and the highest high for a sell... In general the lowest low/high for stop

To fix it, now go to the highest low for buy and the lowest high for sell.

or as follows

StopLoss=MathMin(b0,b1);
StopLoss=MathMax(s0,s1);
 
Swan >> :

Nada to correct, now for buy the biggest low is chosen, and the smallest high for sell.

Logically it is, all right!) This is the choice for the stop (it is chosen the smallest in ppt. of the two options)

Example:


But your version is better and simpler... I'll correct it, but in reverse) Thanks.

StopLoss=MathMax(b0,b1);
StopLoss=MathMin(s0,s1);

Corrected the code on page 5.

 
ALex2008 >> :

Logically it is, all right!) This is the choice for stop (it is chosen the smallest in ppt. of the two options)



Taki for buy the smallest)

imho better the biggest one and trawl on the first bar, different logic :)


StopLevel.

you can change Enter

void UpTrend()
   {
   if(iOpen(NULL,PERIOD_H4,1) - iClose(NULL,PERIOD_H4,1) <= 0
   && iOpen(NULL,PERIOD_H4,2) - iClose(NULL,PERIOD_H4,2) > 0)
      {
      DellAllOrders();
      Enter=iHigh(NULL,PERIOD_H4,1)+(Ask-Bid)+10*Point;
      if( Enter-Ask< StopLevel) Enter=Ask+ StopLevel;
      OrderSend(Symbol(), OP_BUYSTOP, 0.1, Enter, 0, 0, Enter+ Profit, 0, 0,0, Green);
      }
   }

or open an order

void UpTrend()
   {
   if(iOpen(NULL,PERIOD_H4,1) - iClose(NULL,PERIOD_H4,1) <= 0
   && iOpen(NULL,PERIOD_H4,2) - iClose(NULL,PERIOD_H4,2) > 0)
      {
      DellAllOrders();
      Enter=iHigh(NULL,PERIOD_H4,1)+(Ask-Bid)+10*Point;
      if( Enter-Ask< StopLevel)
      OrderSend(Symbol(), OP_BUY, 0.1, Ask, 0, 0, Ask+ Profit, 0, 0,0, Green);
      else 
      OrderSend(Symbol(), OP_BUYSTOP, 0.1, Enter, 0, 0, Enter+ Profit, 0, 0,0, Green);
      }
   }

or think of something else)

 
Swan писал(а) >>

taki for buy the smallest)

imho better to buy with the highest one and trawl on the first bar, different logic :)

With StopLevel.

you can change Enter

or open an order

or you may come up with something else.)

The open price should be further by StopLevel from Bid or Ask. From the open price take the Take and Stop positions which should also be no closer than the StopLevel. But for them we may use the close block by profit or drawdown.

 
Swan >> :

...imho better the biggest and trawl the first bar, different logic :)

Did it this way too... but the test result is better at the current stop)

 

Corrected the stopplay...

//-------Поиск входа для установки ордеров, удаление старых ордеров и установка новых
void UpTrend(){
     if((iOpen(NULL,PERIOD_H4,1) - iClose(NULL,PERIOD_H4,1) <= 0) &&
        (iOpen(NULL,PERIOD_H4,2) - iClose(NULL,PERIOD_H4,2) > 0)){
         DellAllOrders();
         Enter=iHigh(NULL,PERIOD_H4,1)+(Ask-Bid)+10*Point;
         if(Ask<= Enter- StopLevel){
         RefreshRates();
         OrderSend(Symbol(), OP_BUYSTOP, 0.1, Enter, 0, 0, Enter+ Profit, 0, 0,0, Green);}
      }
  }
void DownTrend(){
     if((iOpen(NULL,PERIOD_H4,1) - iClose(NULL,PERIOD_H4,1) >= 0) &&
        (iOpen(NULL,PERIOD_H4,2) - iClose(NULL,PERIOD_H4,2) < 0)){
         DellAllOrders();
         Enter=iLow(NULL,PERIOD_H4,1)-10*Point;
         if(Bid>= Enter+ StopLevel){
         RefreshRates();
         OrderSend(Symbol(), OP_SELLSTOP, 0.1, Enter, 0, 0, Enter- Profit, 0, 0,0, Green);}
      }
  }

   
//-------Вычисление стопа и утановка
void SetStop(){
      RefreshRates();
      b0=iLow(NULL,PERIOD_H4,0)-10*Point;
      b1=iLow(NULL,PERIOD_H4,1)-10*Point;
      s0=iHigh(NULL,PERIOD_H4,0)+(Ask-Bid)+10*Point;
      s1=iHigh(NULL,PERIOD_H4,1)+(Ask-Bid)+10*Point;
            
         if( Type==0){
            StopLoss=MathMax( b0, b1);//Функция возвращает максимальное из двух числовых значений
            if(Bid- StopLoss< StopLevel) StopLoss=MathMin( b0, b1); 
            else OrderModify(OrderTicket(),OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);
         }
         if( Type==1){
            StopLoss=MathMin( s0, s1);//Функция возвращает минимальное из двух числовых значений
            if( StopLoss-Ask< StopLevel) StopLoss=MathMax( s0, s1);
            else OrderModify(OrderTicket(),OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);
         }
   }


Swan >> :

...or open an order straight away.

(It's much safer to enter with pending orders) Otherwise, your brokerage company or nofarms will open you very far...))

>> tweaked the code.

 
ALex2008 >> :

Corrected the stopgap...


(It's better to use pending orders) Otherwise, the DC will show something or nofarms will open you very far...))

>> fixed the code.

Fix old bugs, add new ones :D


Fixed it too)

//+------------------------------------------------------------------+
//|                                                    CandyLite.mq4 |
//|                                                    Ш.Александр.В |
//|                                              shestovav@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Ш.Александр.В"
#property link      "shestovav@gmail.com"

#include <stdlib.mqh>

extern double Profit = 3000;

int Type, Ticket;
double Stop, StopLevel, b0, b1, s0, s1, StopLoss, Enter;
bool dwn, up, mod;

int init(){
   Profit*=Point; 
   return(0);
  }

int deinit() {
   return(0);
  }

int start() {
   StopLevel=Point*MarketInfo(Symbol(),MODE_STOPLEVEL);   // вычисление стоплевел //Point*
   
   if(! WorkOrders()){
      UpTrend();
      DownTrend();
   }
      
   if( WorkOrders()){
      if (( Type<=1)&& ( Stop==0)) SetStop();
      if (( Type==1)||( Type==5)) UpTrend();
      if (( Type==0)||( Type==4)) DownTrend();
   }

   return(0);
  }
//-------Поиск входа для установки ордеров, удаление старых ордеров и установка новых
void UpTrend(){
     if((iOpen(NULL,PERIOD_H4,1) - iClose(NULL,PERIOD_H4,1) <= 0) &&
        (iOpen(NULL,PERIOD_H4,2) - iClose(NULL,PERIOD_H4,2) > 0)){
         DellAllOrders();
         Enter=iHigh(NULL,PERIOD_H4,1)+(Ask-Bid)+10*Point;
         if(Ask< Enter- StopLevel+0.5*Point){
         OrderSend(Symbol(), OP_BUYSTOP, 0.1, Enter, 0, 0, Enter+ Profit, 0, 0,0, Green);}
      }
  }
void DownTrend(){
     if((iOpen(NULL,PERIOD_H4,1) - iClose(NULL,PERIOD_H4,1) >= 0) &&
        (iOpen(NULL,PERIOD_H4,2) - iClose(NULL,PERIOD_H4,2) < 0)){
         DellAllOrders();
         Enter=iLow(NULL,PERIOD_H4,1)-10*Point;
         if(Bid> Enter+ StopLevel-0.5*Point){
         OrderSend(Symbol(), OP_SELLSTOP, 0.1, Enter, 0, 0, Enter- Profit, 0, 0,0, Green);}
      }
  }

//-------Вычисление стопа и установка
void SetStop(){
      RefreshRates();
      b0=iLow(NULL,PERIOD_H4,0)-10*Point;
      b1=iLow(NULL,PERIOD_H4,1)-10*Point;
      s0=iHigh(NULL,PERIOD_H4,0)+(Ask-Bid)+10*Point;
      s1=iHigh(NULL,PERIOD_H4,1)+(Ask-Bid)+10*Point;
            
         if( Type==0){
            StopLoss=MathMax( b0, b1);//Функция возвращает максимальное из двух числовых значений
            if(Bid- StopLoss< StopLevel-0.5*Point) StopLoss=MathMin( b0, b1); 
            if(Bid- StopLoss> StopLevel-0.5*Point)//можно попробовать убрать строку
            OrderModify(OrderTicket(),OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);
         }
         if( Type==1){
            StopLoss=MathMin( s0, s1);//Функция возвращает минимальное из двух числовых значений
            if( StopLoss-Ask< StopLevel-0.5*Point) StopLoss=MathMax( s0, s1);
            if( StopLoss-Ask> StopLevel-0.5*Point)//можно попробовать убрать строку
            OrderModify(OrderTicket(),OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);
         }
   }
   
//-------Удаление всех ордеров, открытых и отложенных
void DellAllOrders(){
      if( WorkOrders()){
      if( Type<=1)OrderClose( Ticket,OrderLots(),OrderClosePrice(),10);
      else OrderDelete( Ticket);}
  }
  
//-------Поиск ордеров
bool WorkOrders(){
      for (int i=OrdersTotal()-1; i>=0; i--){
      if (!OrderSelect( i, SELECT_BY_POS))  continue;
      if (OrderSymbol()!=Symbol())        continue;
      Type  = OrderType();
      Ticket=OrderTicket();
      Stop  =OrderStopLoss();
      return(true);}
  return(false);
  }
 
Swan >> :

Fix old bugs, add new ones :D

what for?

0.5*Point

And MarketInfo() returns type double, why convert it to Point...?

That too... two conditions.


if(Bid- StopLoss< StopLevel-0.5*Point) StopLoss=MathMin( b0, b1); 
if(Bid- StopLoss> StopLevel-0.5*Point)//можно попробовать убрать строку

I think that's all I noticed. It's better to explain what was changed for) So I can keep it in mind for the future.)

 
ALex2008 >> :

I don't understand...)

And MarketInfo() returns type double, why convert it to Point...?

This one too...


0.5*Point is a delta, you can also convert it to 0.7 :)

See comparison of real numbers.

will probably work properly without it. in most cases)


the error was

MarketInfo(Symbol(),MODE_STOPLEVEL)

it returns a value in pips. multiplied by Point.


It was

            if(Bid- StopLoss< StopLevel) StopLoss=MathMin( b0, b1); 
            else OrderModify(OrderTicket(),OrderOpenPrice(), StopLoss,OrderTakeProfit(),0,Red);

if true StopLoss is assigned a new value,

Otherwise the order is modified.

no error, but I have to take off either a cross or put on trousers)