Can someone please tell me what is wrong with this code

To add comments, please log in or register
Mccallum28
354
Mccallum28  

Hi all,

I dont know what I have done wrong here. The EA opens a trade as soon as its loaded regarrdless of when the signal in the indicator fired i.e X bars ago.

Also it only opens buy positions. Can someone help please.

//+------------------------------------------------------------------+//| A Daytrader.mq4 |//| RG |//| |//+------------------------------------------------------------------+

//---- input parameters

extern double TakeProfit=70.0;extern double Lots=3;extern double TrailingStop=15.0;//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init() {//---- //---- return(0); }//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit() {//---- //---- return(0); }

//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start() {//----

int cnt, ticket, total; double ArrowUp, ArrowDown; if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } ArrowUp = iCustom(NULL,0,"PZ_DayTrading",0,1); ArrowDown = iCustom(NULL,0,"PZ_DayTrading",1,1); total = OrdersTotal(); if(total 0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } return(0); } else if (ArrowDown!=2) {

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"DayTrader",12345,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } return(0); } return(0); } for(cnt=0;cnt<total;cnt++) return(0); }//+-----------------------------------------------------------
Mladen Rakic
153905
Mladen Rakic  
rg83:
Hi all,

I dont know what I have done wrong here. The EA opens a trade as soon as its loaded regarrdless of when the signal in the indicator fired i.e X bars ago.

Also it only opens buy positions. Can someone help please.

//+------------------------------------------------------------------+//| A Daytrader.mq4 |//| RG |//| |//+------------------------------------------------------------------+

//---- input parameters

extern double TakeProfit=70.0;extern double Lots=3;extern double TrailingStop=15.0;//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init() {//---- //---- return(0); }//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit() {//---- //---- return(0); }

//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start() {//----

int cnt, ticket, total; double ArrowUp, ArrowDown; if(Bars<100) { Print("bars less than 100"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); // check TakeProfit } ArrowUp = iCustom(NULL,0,"PZ_DayTrading",0,1); ArrowDown = iCustom(NULL,0,"PZ_DayTrading",1,1); total = OrdersTotal(); if(total 0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } return(0); } else if (ArrowDown!=2) {

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"DayTrader",12345,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } return(0); } return(0); } for(cnt=0;cnt<total;cnt++) return(0); }//+-----------------------------------------------------------

rg83

Attach the mq4 file

The code is messed up this way - I don't think that people can check it this way

Mccallum28
354
Mccallum28  
mladen:
rg83

Attach the mq4 file

The code is messed up this way - I don't think that people can check it this way

daytrader_first_ea.mq4

Here is the mq4 file. Thanks.

Files:
Mladen Rakic
153905
Mladen Rakic  
rg83:
daytrader_first_ea.mq4 Here is the mq4 file. Thanks.

rg83

Try replacing :

(ArrowUp!=1) with (ArrowUp!=EMPTY_VALUE)

(ArrowDown!=2) with (ArrowDown!=EMPTY_VALUE)

Mccallum28
354
Mccallum28  
mladen:
rg83

Try replacing :

(ArrowUp!=1) with (ArrowUp!=EMPTY_VALUE)

(ArrowDown!=2) with (ArrowDown!=EMPTY_VALUE)

Tried that and it still only opens buy orders and not at the point when the indicator fires. I have attached the indicator. Maybe I have the wrong buffer. Thank you for your help.

Files:
Mccallum28
354
Mccallum28  
rg83:
Tried that and it still only opens buy orders and not at the point when the indicator fires. I have attached the indicator. Maybe I have the wrong buffer. Thank you for your help.

https://www.mql5.com/en/charts/3681899/eurusd-m15-fxprimus-ltd

As you can see a long position was opened two bars after the signal when it should have been a short on the next bar. any ideas_

Mladen Rakic
153905
Mladen Rakic  
rg83:
https://www.mql5.com/en/charts/3681899/eurusd-m15-fxprimus-ltd As you can see a long position was opened two bars after the signal when it should have been a short on the next bar. any ideas_

rg83

Will have to check exactly how pz daytrading indicator works (not familiar with it). Only after that can tell more

Mladen Rakic
153905
Mladen Rakic  
rg83:
https://www.mql5.com/en/charts/3681899/eurusd-m15-fxprimus-ltd As you can see a long position was opened two bars after the signal when it should have been a short on the next bar. any ideas_

rg83

Been checking the pz-daytrade indicator on a 1 minute chart and it seems to be causing a mess sometimes. Almost sure that your problems are originating from the indicator

Mccallum28
354
Mccallum28  

Thanks Mladen, when i start the EA it instantly opens a trade, would this be an issue with the way i have coded my order entries

To add comments, please log in or register