[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 741

 

I've got it in the expert's office.

bool b=0,s=0, //соответственно бай или селл  
bs=0,// если закрытие по стоплоссу ордера бай
ss=0,// если закрытие по стоплоссу ордера sell
bt=0,
st=0;//      то же по ТП
double bl=0,sl=0; // лоты соответсвенно для бай и селл


for(int cnt=OrdersHistoryTotal();cnt>0;cnt--)
     {
OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
{if(OrderMagicNumber()== mag &&
OrderSymbol()==Symbol()) 
{ if (OrderType() == OP_BUY )  {b=1; if (OrderClosePrice()==OrderTakeProfit()) bt=1; if (OrderClosePrice()==OrderStopLoss()) bs=1; bl=OrderLots()*10; break;}
if (OrderType() == OP_SELL)  {s=1; if (OrderClosePrice()==OrderTakeProfit()) st=1; if (OrderClosePrice()==OrderStopLoss()) ss=1; sl=OrderLots()*10; break;}
            }
         }
      }


}//end

if(bs==1||bl==1)
{   
    NewOrder1(OP_BUYLIMIT,Lot);
    
    Today=TimeDay(TimeCurrent());}
    

int NewOrder1(int Cmd,double Lot)
{double TP=0; //тейкпрофит
double SL=0; //стоплосс
double PR=0; //Цена
double LT=0; //Лот
while(!IsTradeAllowed()) Sleep(100);
if(Cmd==OP_BUYLIMIT)
   {PR=Ask-Point*h;
    if(TakeProfit>0) TP=PR+TakeProfit*Point;
    if(StopLoss>0) SL=PR-StopLoss*Point;
    if(Lot>0) LT=3*Lot;}
int tic1=OrderSend(Symbol(),Cmd,LT,PR,3,SL,TP,0,mag,0,CLR_NONE);

if(tic1<0) Print(GetLastError());

return(0);}





 
artmedia70:
The Boolean variables are not initially initialized to false, in general, before entering the loop, set them to zero (false) - when you exit the loop, they will have the values assigned to them in the loop (better true than 1) and they will continue to have these values until the next entry in the loop. If the opening of an order strictly depends on the values of these variables, then, after the order to open an order, check the presence of this position in the market, and if it is present, set the variables to zero (false)

and in the code you can outline

 
artmedia70:
Compare the ADX value on the current bar (or preferably the first bar) with the ADX value on the previous bar (preferably the second bar).

If it's straightforward, it's something like this:

But it is not very nice. It is better to assign ADX values to double variables and work with the variables...






Thank you very much for your help:)
 

Friends! I cannot figure out how to get rid of unnecessary signals that appear when the trend line is reversed. The trend line (descending in the example) is plotted from the largest extremum to the smallest extremum, found within a specified interval of bars. The problem is that as soon as a new lowest extremum appears, the trend line jumps to that extremum (it is designed that way).

But, also on the first bar the trend line builds levels with the value of the trend line, the crossing of which by the indicator line gives a signal. If the indicator line on the first bar is below this level and on the second bar it is above this level, then we have a top-down crossover.

So... When the trend line jumps to a new lowest extremum, a situation arises where the indicator line on the second bar is above the trend line and below the plotted level, while on the first bar it is below, i.e., an unnecessary sell signal (in this case):


In the picture you can see how the trend line jumped to a new extremum (location is marked with a down arrow) and the price level of the new trend line on the first bar (horizontal red dash line)
became lower than the AD line on the second bar and the AD line on the first bar is lower than the price level...
Accordingly, by moving the trend line to a lower extremum an unwanted signal was simulated... The same unnecessary signal occurred earlier -
I marked it with a vertical light blue line...

Hence the question - how to avoid this situation? I'm exhausted trying to think of something...
Any thoughts? Thanks... :)

 
profitinvesting:
Thank you very much for your help:)
You're welcome :)
 
ToLik_SRGV:

At the very beginning of the start function, add a call line to this function:

The advisor will be activated 1 time, only on a new bar.

Dear Anatoly. Thank you very much for this code. Another question, how to make it work all the time, but it can make only 1 deal on a bar?
 
artmedia70:
after an order to open an order check if the position is already in the market and if it is, reset the variables (false)

Tell me how this can be implemented in my order ?

What function should I insert in my orders to reset them to zero?

 
FoxUA:

Tell me how this can be implemented in my order ?

What function should I insert in my order to reset it to zero ?


Simply after checking if the order is in the market assign values to variables. For example Variable1 = false;
Those variables that you have set to "true" in the loop, which was the criterion for placing the order, must be set to "false" again after the order is placed, otherwise the orders will continue to be placed in batches. So, you should assign these variables to "false".
 
artmedia70:
After checking if there is an order in the market, just assign values to the variables. For example Variable1 = false;
Those variables that you have set to "true" in the loop, which was the criterion for placing the order, must again be set to "false" after the order has been placed. So, you should assign these variables to "false".

I must say I've been up for two days trying to figure out what to place from what you said, so I haven't understood anything. Would you mind putting these values in the code I posted or just write a function and tell me exactly where to put it - this is the last part of my puzzle and I can't figure out where and how to put it.

 
FoxUA:

I must say that I have not slept for two days and struggled with the Expert Advisor because I do not understand what to put from what you have said, can you put these values in the code that I posted or just write the function and tell me where to put it exactly is the last piece of my puzzle and I can not focus where and how to put it

I don't want to mess with your code (evil, but honest :)). Tell me exactly what you want to get in the end and I'll write you the function you need. Honestly - it will be easier for me. I should handle my own code... :)

... Or go to bed, go to sleep, and the next day all your puzzles will come together... :) That's what I do when I don't get it... By the way, I'm off to bed - it's half past five in the morning...