Strategy Code Snippets

Omegaknight

Well-known member
Joined
May 22, 2019
Posts
51
Likes
36
Anyone have any code snippets for MW they would like to share? Ideally these things would be parts of a strategy that you take from one strategy to the next. Say like a trailing stop or TP/SL calculations. Another thing I would love if someone has something similar available is code to force a strategy to stop trading for the day if a certain amount of ticks have been profited.
 

Omegaknight

Well-known member
Joined
May 22, 2019
Posts
51
Likes
36
Anyone have a piece of code they are willing to share that calculates open P/L on a trade and can then decide to close it out if it has hit a target?

I'm having issues generating an early TP signal. When I use the code below, all my trades close out as soon as they are opened and I can't find anything in the SDK that has clear examples on what I am trying to do.

double profit = ctx.getUnrealizedPnL();
...
...
...
if (profit <= 40) {
ctx.closeAtMarket();
}


Any ideas anyone?
 

Spin

Well-known member
Joined
May 22, 2019
Posts
477
Likes
191
Hmmm, shouldn't that read

if (profit >= 40) {
ctx.closeAtMarket();
}

???

Because, right after opening a trade its UnrealizedPnl will always be smaller than 40, so it will closeAtMarket, no ?
 
Top