lots multiplier i wrote not working

 

hi , i just wrote a code to multiply the lot size after every loss because of the high win rate of my ea, as far as i am i got no errors just some signals to check again orderclose and ordersend the problem is that i don't know why it doesn't apply the stop loss so i can't make it work can someone help to fix it or suggest another way to make a lot multiplier, thanks in advance. (the conditions for long and short op i putted in this code are not the same i use on mine it was just to show it to you and if you want to try it so you can help me)

int MagicNumber  = 22220;
int MagicNumber2 = 22221;
int MagicNumber3 = 22222;
int MagicNumber4 = 22223;

extern bool EnableTimeFilter = true;
extern string Start_Hour = "00:00";
extern string End_Hour = "07:00";

extern double Lots = 0.01;
extern double LotsMultiplier = 0.02;
extern int StopLossPoints = 500;
extern int TakeProfitPoints = 500;

//StopLoss------------------------------------------------------------------------------------------------------
double   stopLoss       =  StopLossPoints*SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT);
double   stopLossPrice  =  (OrderType()==ORDER_TYPE_BUY) ?
                                       OrderOpenPrice()-stopLoss :
                                       OrderOpenPrice()+stopLoss;
//TakeProfit----------------------------------------------------------------------------------------------------
double   TakeProfit       =  TakeProfitPoints*SymbolInfoDouble(OrderSymbol(), SYMBOL_POINT);
double   TakeProfitPrice  =  (OrderType()==ORDER_TYPE_BUY) ?
                                       OrderOpenPrice()+TakeProfit :
                                       OrderOpenPrice()-TakeProfit;
void OnTick()
{                      
   //Buy----------------------------------------------
                      
    if( !CondizioniApertura() && EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==true )
    {
    int ticket_ = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,stopLossPrice,TakeProfitPrice,"Buy",MagicNumber2,0,clrNONE);
    }    
       
   //Sell---------------------------------------------
   
    if( !CondizioniApertura() && EnableTimeFilter&&TimeFilter(Start_Hour,End_Hour)==true )
    {
    int _ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,0,stopLossPrice,TakeProfitPrice,"Sell",MagicNumber,0,clrNONE);
    }
  
//Lots Multiplier-------------------------------

int OrdHistory=OrdersHistoryTotal();
int ProfCount=0, LosCount=0;
int Bistory = 3;   

{for(int x=Bistory;x>=1;x--)
{
if(OrderSelect(OrdHistory-x,SELECT_BY_POS,MODE_HISTORY) && stopLossPrice>=0)LosCount++;
if(OrderSelect(OrdHistory-x,SELECT_BY_POS,MODE_HISTORY) && stopLossPrice <0)ProfCount++;
}}

//Sell-------------------------------------------------------------------------------------------
 
   for(int z=Bistory;z>=1;z--)
   {
   if(OrderSelect(z,SELECT_BY_TICKET,MODE_TRADES) && (ProfCount > 1))
   
    if(OrderMagicNumber()==MagicNumber3)
    {
     OrderClose(OrderTicket(), LotsMultiplier, OrderOpenPrice(), 0, clrNONE);
    }  
   OrderSend( Symbol(), OP_SELL, Lots, OrderOpenPrice(), 0, stopLossPrice, TakeProfitPrice, "", MagicNumber ); 
   }

   for(int p=Bistory;p>=1;p--)
   {
   if(OrderSelect(p,SELECT_BY_TICKET,MODE_TRADES) && (LosCount > 1))
   
    if(OrderMagicNumber()==MagicNumber)
    {
     OrderClose( ticket_ , Lots, OrderOpenPrice(), 0, clrNONE);
    } 
  OrderSend( Symbol(), OP_SELL, LotsMultiplier, OrderOpenPrice(), 0, stopLossPrice, TakeProfitPrice, "" , MagicNumber3 );  
  }
  
//Buy---------------------------------------------------------------------------------------------

   for(int o=Bistory;o>=1;o--)
   {
   if(OrderSelect(o,SELECT_BY_TICKET,MODE_TRADES) && (ProfCount > 1))
   
    if (OrderMagicNumber()==MagicNumber4)
    {
      OrderClose( OrderTicket() , LotsMultiplier, OrderOpenPrice(), 0, clrNONE);
    }      
   OrderSend( Symbol(), OP_BUY, Lots, OrderOpenPrice(), 0, stopLossPrice, TakeProfitPrice, "", MagicNumber2 ); 
   }

   for(int t=Bistory;t>=1;t--)
   {
   if(OrderSelect(t,SELECT_BY_TICKET,MODE_TRADES) && (LosCount > 1))
   
    if(OrderMagicNumber()==MagicNumber2)
    {
     OrderClose(_ticket , Lots, OrderOpenPrice(), 0, clrNONE);
    }             
    OrderSend( Symbol(), OP_BUY, LotsMultiplier, OrderOpenPrice(), 0 , stopLossPrice, TakeProfitPrice, "", MagicNumber4 );
  
  }  

//Time---------------------------------------------------------------------------------------------------------

bool TimeFilter(string StartH, string EndH)
{
 datetime Start = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + StartH);
 datetime End = StrToTime(TimeToStr(TimeCurrent(),TIME_DATE) + " " + EndH);
 if(!(Time[0]>=Start&&Time[0]<=End))
 {
 return(false);
 }
 return(true);
 }


 

Please don't post randomly in any section. Your question is not related to the section you posted.

MT4/mql4 has it's own section on the forum.

I have moved your topic to the correct section, please don't create another topic.

Reason: