Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
@Bimi I found the issue and got the code to work, so thank you!
Now I'm trying to figure out how to get the breakeven to work. I have watched the Advanced MC Strategy Video Tutorial that @Big Mike posted and I have used his breakeven code, but it doesn't seem to be reacting like it should. For instance, my second and third lots will get stopped out within two-three pips of my entry price (like they should if my first target has been hit), but they get stopped out before my first target is hit, even in the same bar sometimes.
I've not been able to find any answers to this online or on futures.io (formerly BMT). I'm not opposed to coding it differently than BigMike, I just figured he coded it in the most efficient way.
Also, how difficult do you think it would be to have stops 2 and 3 move to breakeven after target 1 is filled, and then have the last stop change to a trailing stop after target 2 is filled? That is my ultimate goal, but if I need to learn other concepts first I'm definitely willing to do so.
The breakeven to trailing stop switch is where NT fell short in its capabilities for me (due to my limited knowledge of NinjaScript).
If you'd like to see for yourself how it's acting, here is my code:
inputs:
SlowLength (26),
FastLength (12),
MACDLength (9),
Target1 (10),
Target2 (10),
Target3 (10),
StopSize (10),
BE2 (0), // 0=false 1=true
BE3 (0); // 0=false 1=true
vars:
ticksize (MinMove/PriceScale),
MyMACD (0),
MACDAvg (0),
MACDDiff (0),
t1 (Target1 * ticksize),
t2 ((Target1 + Target2) *ticksize),
t3 ((Target1 + Target2 + Target3) * ticksize),
st1 (0),
st2 (0),
st3 (0);
MyMACD = MACD(Close, FastLength, SlowLength);
MACDAvg = XAverage(MyMACD, MACDLength);
MACDDiff = MyMACD - MACDAvg;
// Open new Positions
if MarketPosition = 0 then begin
if MyMACD crosses above MACDAvg and MyMACD <= 0 and MACDAvg <= 0 then begin
Buy ("Enter Long") 300000 contracts next bar at market;
end;
if MyMACD crosses below MACDAvg and MyMACD >= 0 and MACDAvg >= 0 then begin
SellShort ("Enter Short1") 300000 contracts next bar at market;
end;
end;
// Manage open orders
if MarketPosition = 1 then begin
st1 = EntryPrice - (StopSize * ticksize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice - (StopSize * ticksize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice - (StopSize * ticksize));
if CurrentContracts = 100000 then begin
Sell ("Exit l3-c1 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 200000 then begin
Sell ("Exit l2-c2 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c2 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 300000 then begin
Sell ("Exit l1-c3 Target") 100000 Contract Next Bar at (EntryPrice + t1) Limit;
Sell ("Exit l1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
Sell ("Exit l2-c3 Target") 100000 Contract Next Bar at (EntryPrice + t2) Limit;
Sell ("Exit l2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
Sell ("Exit l3-c3 Target") 100000 Contract Next Bar at (EntryPrice + t3) Limit;
Sell ("Exit l3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
if MarketPosition = -1 then begin
st1 = EntryPrice + (StopSize * ticksize);
st2 = iff(BE2 = 1, EntryPrice, EntryPrice + (StopSize * ticksize));
st3 = iff(BE3 = 1, EntryPrice, EntryPrice + (StopSize * ticksize));
if CurrentContracts = 100000 then begin
BuyToCover ("Exit s3-c1 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c1 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 200000 then begin
BuyToCover ("Exit s2-c2 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c2 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c2 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c2 Stop") 100000 Contract Next Bar at st3 Stop;
end;
if CurrentContracts = 300000 then begin
BuyToCover ("Exit s1-c3 Target") 100000 Contract Next Bar at (EntryPrice - t1) Limit;
BuyToCover ("Exit s1-c3 Stop") 100000 Contract Next Bar at st1 Stop;
BuyToCover ("Exit s2-c3 Target") 100000 Contract Next Bar at (EntryPrice - t2) Limit;
BuyToCover ("Exit s2-c3 Stop") 100000 Contract Next Bar at st2 Stop;
BuyToCover ("Exit s3-c3 Target") 100000 Contract Next Bar at (EntryPrice - t3) Limit;
BuyToCover ("Exit s3-c3 Stop") 100000 Contract Next Bar at st3 Stop;
end;
end;
Thank you for your help! I would still be where I was two weeks ago without your help!
@Bimi I found the issue and got the code to work, so thank you!
Now I'm trying to figure out how to get the ...
Slow down... one problem at a time.
What was the problem? Aren't you going to share? This is a community, not your private tech support. Many people read these threads to learn together. The synergy makes us grow faster.
@Bimi I found the issue and got the code to work, so thank you!
...
Also, how difficult do you think it would be to have stops 2 and 3 move to breakeven after target 1 is filled, and then have the last stop change to a trailing stop after target 2 is filled? That is my ultimate goal, but if I need to learn other concepts first I'm definitely willing to do so.
...
You are talking about advanced level EL programming.
It is not difficult, if you have proper programming habits.
You will need to be more careful with the details.
For complex strategies, you must start with a flowchart. There is no short cut.
What was the problem? Aren't you going to share? This is a community, not your private tech support. Many people read these threads to learn together. The synergy makes us grow faster.
There is no "hidden" problem that I was hiding from the forum. I *am* sharing all of my issues because I know that my biggest contribution to this forum is creating discussions where others can learn from my mistakes and from answers to my questions. That's also why I search through the current threads before I ask a question.
I asked about those two issues at the same time because they are related. I wasn't sure if they needed to be coded a certain way to work well with each other (the breakeven and trailing stop). I apologize for the misunderstandings.
Bimi
You are talking about advanced level EL programming.
It is not difficult, if you have proper programming habits.
You will need to be more careful with the details.
For complex strategies, you must start with a flowchart. There is no short cut.
Ok, can you teach me then? You obviously know what you're doing when it comes to coding. I am more than willing to learn, I just need someone to teach me... I have already learned quite a bit I think. I'm not looking for a shortcut.
Perhaps there needs to be a thread that is a tutorial for the basics of EL programming? I have looked for something like that and haven't found it...
@Bimi I found the issue and got the code to work, so thank you!
...
Bimi
Slow down... one problem at a time.
What was the problem? Aren't you going to share? This is a community, not your private tech support. Many people read these threads to learn together. The synergy makes us grow faster.
Please click the [Thanks] button.
Arich
There is no "hidden" problem that I was hiding from the forum. I *am* sharing all of my issues because I know that my biggest contribution to this forum is creating discussions where others can learn from my mistakes and from answers to my questions. That's also why I search through the current threads before I ask a question.
...
I meant... what was the issue that you found on the previous problem.
I meant... what was the issue that you found on the previous problem.
Gotcha, there was a missing "end;" that was causing the error. I had copy and pasted some of the code when I was trying to isolate the previous problem of the code not exiting the positions correctly and forgot to replace the "end;" in between my buy and sell conditions.
I will try to update this thread every time I fix an issue and how I used (your's or any other's) advice. Thanks!
Ok, so I wanted to explain a difference that I noticed between NT and MC when coding entries.
In NT, when you code an entry (in my experience, which is limited) you have to code each lot if your goal is to have multiple targets. For example, if you want to enter a buy and have three targets:
In MC the same entry for three targets looks like this:
//Conditions for entry are here, then:
Buy ("Enter Long") 300000 contracts next bar at Market;
From what I can see, the difference is that NT creates three separate orders which are then tied to three separate exits, while MC groups all the orders together and uses the exits to manage how much is exited at a time.
That's a beginner's interpretation of what is happening. Can anyone confirm or improve my findings?