[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 95

 
PariaH:

Please tell me how to open a new order if a Stop Loss or TP is triggered. Preferably a code! Many thanks in advance!!!

Open any code of an EA from https://www.mql5.com/ru/code

or open the code of the Expert Advisor that comes with MT4, for example, Moving Average.mq4.

There, if you look carefully, you will see how it is done.

After that you will be able to talk.

 

There, if you look carefully, you will see how it is done.

After that, you can talk.

That's not exactly the answer I was expecting... I want a concrete example, not the full code of the programme.. .

 
alexhammer:

I've sketched out a new EA today, I'm writing it for myself, but if it turns out OK I'll share it with you later.

I'd like your opinion on what else to add to it. It can rearrange stop and takei, move the line on the screen, show open orders, and more statistics on the accounts. The most important thing is to add some options for trailing stops and to visually display their movement. What other requests will there be?

It looks nice :).

At least, I want to teach my Expert Advisor not to lose the deposit.

A nice EA is not a guarantee of a nice life.

 
PariaH:

There, if you look carefully, you will see how it is done.

After that, you can talk.

That's not exactly the answer I was expecting... I want a concrete example, not the full code of the programme.. .

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int    res;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
   if(Open[1]>ma && Close[1]<ma)  
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
//---- buy conditions
   if(Open[1]<ma && Close[1]>ma)  
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//----
  }
This is part of the EA code supplied with MT4.
 
coronel:

Teach an EA at least not to lose a deposit.

A beautiful EA is no guarantee of a beautiful life.


Don't lecture me about EAs! This is not a trading EA if you don't understand. And on the screen is a demo account with specially opened orders to test the performance of this EA.
 
alexhammer:

Don't lecture me about EAs! This is not a trading Expert Advisor if you do not understand. And on the screen is a demo account with specially opened orders to test the work of this EA.

Please forgive me if my post sounded preachy.

I was only expressing my point of view regarding autotrading.

 
Come on Peace! :) I was just waiting for some ideas and wishes, I'm not just trying to do it for myself.
 
alexhammer:
Come on, the world! :) I was just waiting to hear some ideas, wishes, not only for myself because I'm trying.

There are tons of ideas on this site, but I don't know anyone who makes a living as an auto-trader.

 
coronel:
This is part of the EA code supplied with MT4.


SPY... But that's not it again :) the thing is, I don't use indicators... I just need to open a new order if a STOP or PREF is triggered! How can this be implemented in another way...

here is part of the code.... but it doesn't work ....

for(int i=1; i<=OrdersTotal(); i++) // ???? ???????? ?????

{

if(OrderSelect(i-1,SELECT_BY_POS)==true)

{

double SL=OrderStopLoss();

double TP=OrderTakeProfit(); // TP ?????????? ???.

double Price =OrderOpenPrice();

{

if(SL >= Price)

{

OrderSend(Symbol(), OP_BUY, lots,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Green);

}

}

Alert(i);

}

}

 
PariaH:


SPS... But that's not it again :) the thing is, I don't use indicators... I just need to open a new order if it triggers STOP or PREF! How can this be implemented in another way...

here's part of the code.... but it doesn't work ....


Still the same piece of code, but without the indicator:

int start()
  {
   int    res;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- 
   if(OrdersTotal()==0)//если нет открытых ордеров
     { 
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);// открыть SELL
 //     res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue); //открыть BUY
     }
//----
 return(0);}

	          
Reason: