strategy refinement of the advisor - page 4

 
IRIP:

Where can I read about how to set a stop loss?

I need, say, a stop at Low bar 2


https://book.mql4.com/ru/trading/index
 
Thank you
 

There are now several challenges

1. Breakeven when a certain profit is reached

2. trawl by fractals or a fixed figure

 
IRIP:

There are now several challenges

1. Breakeven when a certain profit is reached

2. trawl by fractals or a fixed figure


Start writing and ask questions as you go along...
 
IRIP:
if ( ( (Low[0]>Low[1]) && (Low[1]<Low[2]) && (Low[1]<Low[2]) && (High[1]<High[2]) ) BuyOp=true;

if ( ( (High[0]<High[1]) && (Low[0]<Low[1]) && (High[1]>High[2]) && (Open[0]<Close[1]) ) SellOp=true;


Sell . And no Trall or Breakeven will help you. And it will never help if you don't exploit any regularities, like in this case.

 
DYN:


You will. And no trawl or break-even will help you. And it will never help if you do not exploit any regularities as in this case.


It will. But the man is learning to program, and it's not so bad!
 
ktest0:

He will. But one learns to program, and that's not a bad thing!

Yeah, I agree. Kudos to the dude for that. It is difficult to learn from scratch at the beginning - I know how it is -)-)-)
 
ktest0:

He will. But one learns to program, and that's not a bad thing!

Yes, I really want to learn how to program.
 


Books, that's great. But, for example, I found an advisor that generally does what I need

//+------------------------------------------------------------------+

//| TrailingStopLight.mq4 |

//| Copyright © 2011, Khlystov Vladimir |

//| http://cmillion.narod.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, cmillion@narod.ru"

#property link "http://cmillion.narod.ru"

#property show_inputs

//--------------------------------------------------------------------

extern int Stoploss = 0, //stopploss, if 0, remains unchanged

Takeprofit = 0; //takeprofit, if 0, remains unchanged

extern int TrailingStop = 20; //tramp length, if 0, then no trailing stop

extern int StepTrall = 0; //tramp step - move StopLoss no closer than StepTrall

extern int NoLoss = 10, //transfer to Breakeven at a specified number of points profit, if 0, then no transfer to Breakeven

MinProfitNoLoss = 0; //minimum profit for the transfer to breakeven

//--------------------------------------------------------------------

int STOPLEVEL,TimeBar;

//--------------------------------------------------------------------

int init()

{

}

//--------------------------------------------------------------------

int deinit()

{

ObjectDelete("SLb");

ObjectDelete("SLs");

}

//--------------------------------------------------------------------

int start()

{

//while(!IsStopped())

{

//RefreshRates();

STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);

double OSL,OTP,OOP,StLo,SL,TP;

double Profit,ProfitS,ProfitB,LB,LS,NLb,NLs,price_b,price_s,OL,sl;

int b,s,OT,OMN;

for (int i=OrdersTotal()-1; i>=0; i--)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

OMN = OrderMagicNumber();

if (OrderSymbol() == Symbol())

{

OOP = NormalizeDouble(OrderOpenPrice(),Digits);

OT = OrderType();

OL = OrderLots();

if (OT==OP_BUY)

{

price_b = price_b+OOP*OL;

b++; LB+= OL;

ProfitB+=OrderProfit()+OrderSwap()+OrderCommission();

}

if (OT==OP_SELL)

{

price_s = price_s+OOP*OL;

s++;LS+= OL;

ProfitS+=OrderProfit()+OrderSwap()+OrderCommission();

}

}

}

}

ObjectDelete("SLb");

ObjectDelete("SLs");

if (b>0)

{

NLb = NormalizeDouble(price_b/LB,Digits);

ObjectCreate("SLb",OBJ_ARROW,0,Time[0],NLb,0,0,0);

ObjectSet ("SLb",OBJPROP_ARROWCODE,6);

ObjectSet ("SLb",OBJPROP_COLOR,Blue);

}

if (s>0)

{

NLs = NormalizeDouble(price_s/LS,Digits);

ObjectCreate("SLs",OBJ_ARROW,0,Time[0],NLs,0,0,0);

ObjectSet ("SLs",OBJPROP_ARROWCODE,6);

ObjectSet ("SLs",OBJPROP_COLOR,Red);

}

int OTicket;

for (i=0; i<OrdersTotal(); i++)

{

if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

if (OrderSymbol()==Symbol())

{

OT = OrderType();

OSL = NormalizeDouble(OrderStopLoss(),Digits);

OTP = NormalizeDouble(OrderTakeProfit(),Digits);

OOP = NormalizeDouble(OrderOpenPrice(),Digits);

SL=OSL; TP=OTP;

if (OT==OP_BUY)

{

b++;

if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

{

SL = NormalizeDouble(Bid - Stoploss * Point,Digits);

}

else SL=OSL;

if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

{

TP = NormalizeDouble(Ask + Takeprofit * Point,Digits);

}

else TP=OTP;

if (NoLoss>=STOPLEVEL && OSL<NLb && NoLoss!=0)

{

if (OOP<=NLb && NLb!=0 && NLb <= NormalizeDouble(Bid-NoLoss*Point,Digits))

SL = NormalizeDouble(NLb+MinProfitNoLoss*Point,Digits);

}

if (TrailingStop>=STOPLEVEL && TrailingStop!=0)

{

StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits);

if (StLo>=NLb && NLb!=0) if (StLo > OSL) SL = StLo;

}

if (SL != OSL || TP != OTP)

{

OTicket=OrderTicket();

if (!OrderModify(OTicket,OOP,SL,TP,0,White)) Print("OrderModify Error ",GetLastError());

}

}

if (OT==OP_SELL)

{

s++;

if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

{

SL = NormalizeDouble(Ask + Stoploss * Point,Digits)

}

else SL=OSL;

if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

{

TP = NormalizeDouble(Bid - Takeprofit * Point,Digits);

}

else TP=OTP;

if (NoLoss>=STOPLEVEL && (OSL>NLs || OSL==0) && NoLoss!=0)

{

if (OOP>=NLs && NLs!=0 && NLs >= NormalizeDouble(Ask+NoLoss*Point,Digits))

SL = NormalizeDouble(NLs-MinProfitNoLoss*Point,Digits);

}

if (TrailingStop>=STOPLEVEL && TrailingStop!=0)

{

StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits);

if (StLo<=NLs && NLs!=0) if (StLo < OSL || OSL==0) SL = StLo;

}

if ((SL != OSL || OSL==0) || TP != OTP)

{

OTicket=OrderTicket();

if (!OrderModify(OTicket,OOP,SL,TP,0,White)) Print("OrderModify Error ",GetLastError());

}

}

}

}

}

if (IsTesting())

{

if (TimeBar!=Time[0])

{

OrderSend(Symbol(),OP_BUY,1,NormalizeDouble(Ask,Digits),3,0,0, "test",0,0,Blue);

OrderSend(Symbol(),OP_SELL,1,NormalizeDouble(Bid,Digits),3,0,0, "test",0,0,Red);

TimeBar=Time[0];

}

}

//Sleep(1000);

}

}

//--------------------------------------------------------------------

Could it (theoretically) be inserted into mine?

 
IRIP:


Books, that's great. But, for example, I found an advisor that generally does what I need

//+------------------------------------------------------------------+

//|                                            TrailingStopLight.mq4 |

//|                              Copyright © 2011, Khlystov Vladimir |

//|                                         http://cmillion.narod.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, cmillion@narod.ru"

#property link      "http://cmillion.narod.ru"

#property show_inputs

//--------------------------------------------------------------------
extern int Stoploss             = 0,//стоплосс, если 0 то не изменяется
           Takeprofit           = 0;//тейкпрофит, если 0 то не изменяется
extern int TrailingStop         = 20;//длинна тралла, если 0 то нет тралла
extern int StepTrall            = 0;//шаг тралла - перемещать стоплосс не ближе чем StepTrall
extern int NoLoss               = 10,//перевод в безубыток при заданном кол-ве пунктов прибыли, если 0 то нет перевода в безубыток
           MinProfitNoLoss      = 0//минимальная прибыль при переводе вбезубыток
//--------------------------------------------------------------------
int  STOPLEVEL,TimeBar;
//--------------------------------------------------------------------
int init()
{

}
//--------------------------------------------------------------------
int deinit()
{
   ObjectDelete("SLb");
   ObjectDelete("SLs");
}
//--------------------------------------------------------------------
int start()                                  
{
   //while(!IsStopped())
   {
      //RefreshRates();
      STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
      double OSL,OTP,OOP,StLo,SL,TP;
      double Profit,ProfitS,ProfitB,LB,LS,NLb,NLs,price_b,price_s,OL,sl;
      int b,s,OT,OMN;
      for (int i=OrdersTotal()-1; i>=0; i--)
      {                                               
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol())
            {
               OOP = NormalizeDouble(OrderOpenPrice(),Digits);

               OT = OrderType();
               OL = OrderLots();
               if (OT==OP_BUY)
               {
                  price_b = price_b+OOP*OL;
                  b++; LB+= OL;
                  ProfitB+=OrderProfit()+OrderSwap()+OrderCommission();
               }
               if (OT==OP_SELL)
               {
                  price_s = price_s+OOP*OL;

                  s++;LS+= OL;

                  ProfitS+=OrderProfit()+OrderSwap()+OrderCommission();

               }

            }

         }

      }

      ObjectDelete("SLb");

      ObjectDelete("SLs");

      if (b>0) 

      {

         NLb = NormalizeDouble(price_b/LB,Digits);

         ObjectCreate("SLb",OBJ_ARROW,0,Time[0],NLb,0,0,0,0);                     

         ObjectSet   ("SLb",OBJPROP_ARROWCODE,6);

         ObjectSet   ("SLb",OBJPROP_COLOR, Blue);

      }

      if (s>0) 

      {

         NLs = NormalizeDouble(price_s/LS,Digits);

         ObjectCreate("SLs",OBJ_ARROW,0,Time[0],NLs,0,0,0,0);                     

         ObjectSet   ("SLs",OBJPROP_ARROWCODE,6);

         ObjectSet   ("SLs",OBJPROP_COLOR, Red);

      }

      int OTicket;

      for (i=0; i<OrdersTotal(); i++)

      {    

         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

         {

            if (OrderSymbol()==Symbol())

            { 

               OT = OrderType(); 

               OSL = NormalizeDouble(OrderStopLoss(),Digits);

               OTP = NormalizeDouble(OrderTakeProfit(),Digits);

               OOP = NormalizeDouble(OrderOpenPrice(),Digits);

               SL=OSL;TP=OTP;

               if (OT==OP_BUY)             

               {  

                  b++;

                  if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

                  {

                      SL = NormalizeDouble(Bid - Stoploss   * Point,Digits);

                  } 

                  else SL=OSL;

                  if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

                  {

                      TP = NormalizeDouble(Ask + Takeprofit * Point,Digits);

                  } 

                  else TP=OTP;

                  if (NoLoss>=STOPLEVEL && OSL<NLb && NoLoss!=0)

                  {

                     if (OOP<=NLb && NLb!=0 && NLb <= NormalizeDouble(Bid-NoLoss*Point,Digits)) 

                        SL = NormalizeDouble(NLb+MinProfitNoLoss*Point,Digits);

                  }

                  if (TrailingStop>=STOPLEVEL && TrailingStop!=0)

                  {

                     StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits); 

                     if (StLo>=NLb && NLb!=0) if (StLo > OSL) SL = StLo;

                  }

                  if (SL != OSL || TP != OTP)

                  {  

                     OTicket=OrderTicket();

                     if (!OrderModify(OTicket,OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());

                  }

               }                                         

               if (OT==OP_SELL)        

               {

                  s++;

                  if (OSL==0 && Stoploss>=STOPLEVEL && Stoploss!=0)

                  {

                     SL = NormalizeDouble(Ask + Stoploss   * Point,Digits);

                  }

                  else SL=OSL;

                  if (OTP==0 && Takeprofit>=STOPLEVEL && Takeprofit!=0)

                  {

                      TP = NormalizeDouble(Bid - Takeprofit * Point,Digits);

                  }

                  else TP=OTP;

                  if (NoLoss>=STOPLEVEL && (OSL>NLs || OSL==0) && NoLoss!=0)

                  {

                     if (OOP>=NLs && NLs!=0 && NLs >= NormalizeDouble(Ask+NoLoss*Point,Digits)) 

                        SL = NormalizeDouble(NLs-MinProfitNoLoss*Point,Digits);

                  }

                  if (TrailingStop>=STOPLEVEL && TrailingStop!=0)

                  {

                     StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits); 

                     if (StLo<=NLs && NLs!=0) if (StLo < OSL || OSL==0) SL = StLo;

                  }

                  if ((SL != OSL || OSL==0) || TP != OTP)

                  {  

                     OTicket=OrderTicket();

                     if (!OrderModify(OTicket,OOP,SL,TP,0,White)) Print("Error OrderModify ",GetLastError());

                  }

               } 

            }

         }

      }

      if (IsTesting())

      {

         if (TimeBar!=Time[0])

         {

            OrderSend(Symbol(),OP_BUY,1,NormalizeDouble(Ask,Digits),3,0,0,"тест",0,0,Blue);

            OrderSend(Symbol(),OP_SELL,1,NormalizeDouble(Bid,Digits),3,0,0,"тест",0,0,Red);

            TimeBar=Time[0];

         }

      } 

      //Sleep(1000);

   } 
}
//--------------------------------------------------------------------

Can it (theoretically) be inserted into mine?

First, learn how to insert code with an SRC button!

That "books are great" needs to be demonstrated yet! In the meantime, you're thinking of getting out on hints. And "without labour...", you probably know the result, or you'll find out, and time is running out! Without knowledge only to nowhere!