Reply

Open trade on new candle

27 replies

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #112139

HI

 

I just want a rule that says as soon as a new candle opens, then enter a trade.  Can anyone tell me how?\

 

Thanks

 

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124663

On the Open P/L I can see it has a magic number, so its only going to look at the trade with that magic number.  The only thing I can think of is that the value in pips of both trades should be assigned a variable each, and then the two variables added together.  I just can’t see how to do it?

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124664

I think I solved that.  But its still not opening trades on the 2nd currency pair.  Can you take a look at the strategy file attached and see if I have done anything wrong?

 

Thanks

File: Hedge.sqw

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124665

hmm fixed it.  

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124668

One last problem with this strategy…

I am adding the open p/l together for both currencies and the rule is, if the total profit is >= 5 pips then close both trades.

However, its closing at 5 pips regardless of whether its 5 pips profit or 5 pips loss, or 3 pips profit and 2 pips loss etc.

How do I ensure it only closes when the open p/l is positive 5 pips?

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124734

I am adding the open p/l together for both currencies and the rule is, if the total profit is >= 5 pips then close both trades.

However, its closing at 5 pips regardless of whether its 5 pips profit or 5 pips loss, or 3 pips profit and 2 pips loss etc.

How do I ensure it only closes when the open p/l is positive 5 pips?

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

9 years ago #124737

can you attach your strategy here? it should recognize between positive and negative PL.

Mark
StrategyQuant architect

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124740

Here it is.

File: Hedge.sqw

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

9 years ago #124765

I looked at this, the problem is that the function Open PL always checks the PL only in current chart symbol. It is because you can use 0 as magic number, 
and it will return open profit for all trades on the same symbol.

The solution is to use custom function, but don’t worry, it is not complicated.

Open file EA Wizard/code/CustomFunctions.mq4 and add the following function there:

 
double sqGetOpenPLInPips2(int MN1, int MN2) {
   double pl = 0;
 
   for (int cc = OrdersTotal() – 1; cc >= 0; cc–) {
      if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
      if(OrderType() != OP_BUY && OrderType() != OP_SELL) continue;
      if(OrderMagicNumber() != MN1 && OrderMagicNumber() != MN2) continue;
 
      if(OrderType() == OP_BUY) {
         pl += sqGetBid(OrderSymbol()) – OrderOpenPrice();
      } else {
         pl += OrderOpenPrice() – sqGetAsk(OrderSymbol());
      }
   }
 
   return(pl*gPointPow);
}
 
then you can use this custom function in EA Wizard, I’m attaching a strategy that shows how to call it to get PL of two orders with different magic numbers combined.
 
 
File: Hedge.sqw

Mark
StrategyQuant architect

0

slowbutsure

Subscriber, bbp_participant, community, 63 replies.

Visit profile

9 years ago #124778

Thanks Mark, thats very helpful.

0

Eddiebund

Subscriber, bbp_participant, community, 21 replies.

Visit profile

9 years ago #125372

Mark

 

This is a very interesting strategy which I was looking test.  Unfortunately, when i add the code above to CustomFunctions it doesn’t compile and shows the errors

 

‘sqGetBid’ – function not defined CustomFunctions2.mq4 29 16
‘sqGetAsk’ – function not defined CustomFunctions2.mq4 31 35
‘gPointPow’ – undeclared identifier CustomFunctions2.mq4 35 14
event handling function not found 1 1
4 error(s), 0 warning(s) 5 1
 

 

Actually when I removed the additional code the last 2 errors still exist

 

Can you advise please

 

Thanks

 

Eddie

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

9 years ago #125394

Hello Eddie,

 

are you trying to compile the COmpiledFunctions.mq4 file by itself?

 

It isn’t supposed to work like this. The contents of this file is attached to every EA created in EA Wizard, so don’t compile this custom file, but normal EA that you export from EA Wizard.

It should have these functions already included.

Mark
StrategyQuant architect

0

Eddiebund

Subscriber, bbp_participant, community, 21 replies.

Visit profile

9 years ago #125409

Thanks for that Mark

 

It is now working and gives me the basis of something to try and develop

 

 

Cheers

0

Viewing 12 replies - 16 through 27 (of 27 total)

1 2