[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 465

 
extralifes:

Help me understand the code. I don't know how to describe the condition correctly.

Here's a piece of the EA.

if(total<1)

{

while (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2) //Пока это условие выполняется открывать только селл при таком условии (iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7)&&(iRSI(NULL,0,rsi_period,PRICE_CLOSE,0)<0.7)) -какой оператор использовать и как его оформить?
{
OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 3, /*Ask+10*Point*/0, /*Bid-10*Point*/0, "ADX sell", magic, 0, CLR_NONE);
}

while (d_pl_1>d_mn_1 && (d_pl_0-d_mn_0)>=2) // Пока это условие выполняется открывать только Бай при таком условии (iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)<0.3)&&(iRSI(NULL,0,rsi_period,PRICE_CLOSE,0)>0.3)) - какой оператор использовать и как его оформить?
{
OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask, Digits), 3, /*Bid-10*Point*/0, /*Ask+10*Point*/0, "ADX buy", magic, 0, CLR_NONE);

}
}
}
}
Some kind of vegetable garden....
 
butthead:

I understand that the psychological factor prevents me... greed... the fear of losing even 300 p... What should I do?... Forget that the real account...


What if I change my mindset? Not "aim to win", but "aim not to lose".
 

Help to understand!

The essence of the idea: while iMACD is increasing - we keep BUY, as soon as it starts to decrease - we close BUY and open SELL. Comparison is done using the last three values, excluding the current one.

The code has a problem: it opens multiple orders at iMACD values +-0, as I see. Normalizedouble() does not help.

Here is the code:

int start()
  {

double MA1=iMACD(NULL,0,5,34,1,PRICE_CLOSE, MODE_MAIN,1), 
       MA2=iMACD(NULL,0,5,34,1,PRICE_CLOSE, MODE_MAIN,2),
       MA3=iMACD(NULL,0,5,34,1,PRICE_CLOSE, MODE_MAIN,3);
       
       
       
if (MA1>MA2>MA3 && Napr==1)
    {Closeall();
    Napr=0;
    OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0,0);}

if (MA1<MA2<MA3 && Napr==0)
    {Closeall();
    Napr=1;
    OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0,0);}



   return(0);
  }
 
extralifes:

Help me understand the code. I don't know how to describe the condition correctly.

Here is a piece of the Expert Advisor.


total=OrdersTotal();

if(total<1)

{

while (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2) //Пока это условие выполняется открывать только селл при таком условии (iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7)&&(iRSI(NULL,0,rsi_period,PRICE_CLOSE,0)<0.7)) -какой оператор использовать и как его оформить?
{
OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 3, /*Ask+10*Point*/0, /*Bid-10*Point*/0, "ADX sell", magic, 0, CLR_NONE);
}

while (d_pl_1>d_mn_1 && (d_pl_0-d_mn_0)>=2) // Пока это условие выполняется открывать только Бай при таком условии (iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)<0.3)&&(iRSI(NULL,0,rsi_period,PRICE_CLOSE,0)>0.3)) - какой оператор использовать и как его оформить?
{
OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask, Digits), 3, /*Bid-10*Point*/0, /*Ask+10*Point*/0, "ADX buy", magic, 0, CLR_NONE);

}
}
}
}
Can you tell me how to do it properly?


Does it not work like this?

total=OrdersTotal();
if(total<1)

{

  if (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7 &&  iRSI(NULL,0,rsi_period,PRICE_CLOSE,0<0.7)
        OrderSend(Symbol(), OP_SELL, lots, NormalizeDouble(Bid, Digits), 3, /*Ask+10*Point*/0, /*Bid-10*Point*/0, "ADX sell", magic, 0, CLR_NONE);
   

  if (d_pl_1>d_mn_1 && (d_pl_0-d_mn_0)>=2 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)<0.3 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,0) > 0.3) 
       OrderSend(Symbol(), OP_BUY, lots, NormalizeDouble(Ask, Digits), 3, /*Bid-10*Point*/0, /*Ask+10*Point*/0, "ADX buy", magic, 0, CLR_NONE);

  }
 

no through if does not work.

It should be as long as the condition (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2 is correct, to open only an order for a sell if iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,0<0.7)

It is the same in reverse.

Can it be done through while or bool? I'm in a complete crunch in programming. I understand the logical chain, but my hands are slow to convert it into code.

 
extralifes:

no through if does not work.

It should beas long as the condition (d_mn_1>d_pl_1 && (d_mn_0-d_pl_0)>=2 is correct, to open only an order to sell provided that iRSI(NULL,0,rsi_period,PRICE_CLOSE,2)>0.7 && iRSI(NULL,0,rsi_period,PRICE_CLOSE,0<0.7)

It is the same in reverse.

Can it be written through while or bool? I'm in a complete crunch in programming. I understand the logical chain, but my hands are slow to convert it into code.

open until money runs out? or open once per bar? or once per tick?
 

Hello! I don't want to (and sometimes do) get caught by StopOut. I decided to limit the lot with a value, which would not catch StopOut in the worst conditions. Going through trial and error for a long time. Maybe someone has a solution?

Input data:

- currency pair - not necessarily EURUSD

- price (buy/sell price)

- specified StopLoss in points (it is assumed that the worst-case scenario is not to catch a StopOut even if the StopLoss level is reached)

- set value of lot

- All other values should be obtained using MT4 functions: Size of 1 lot, leverage, cross rate.

A code would be desirable.

In theory I understand what I need: balance minus possible loss at StopLoss level divided by margin. And this value should be greater than StopOut (in percentage terms)

 
Cmu4:

Help to understand!

The essence of the idea: while iMACD is increasing - we keep BUY, as soon as it starts to decrease - we close BUY and open SELL. Comparison is done using the last three values, excluding the current one.

The code has a problem: it opens multiple orders at iMACD values +-0, as I see. Normalizedouble() does not help.

Here is the code:


int start()
  {

double MA1=iMACD(NULL,0,5,34,1,PRICE_CLOSE, MODE_MAIN,1), 
       MA2=iMACD(NULL,0,5,34,1,PRICE_CLOSE, MODE_MAIN,2),
       MA3=iMACD(NULL,0,5,34,1,PRICE_CLOSE, MODE_MAIN,3);
       
       
       
if (MA1>MA2 &&  MA2>MA3 && Napr==1)
    {Closeall();
    Napr=0;
    OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0,0);}

if (MA1<MA2 && MA2<MA3 && Napr==0)
    {Closeall();
    Napr=1;
    OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0,0);}



   return(0);
  }
Maybe that was the problem
 
ilunga:
open until the money runs out? or open once per bar? or once per tick?

The condition is checked every new bar. In this case, the time frame is hourly. This condition is checked at the beginning of each hour.
 
Vinin:

Maybe this was the problem

No... I did as you suggested - the same thing remains.

Also, I changed the code, dividing separately into opening and closing blocks by conditions. It's all the same. I do not know what to do now.

Here is a screenshot from tester, Expert Advisor for tester in trailer:

Files: