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)
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1
Hello fellow coders,
I consider myself to be a moderate Easy Language coder.
I have coded for a Strategy that if its conditions are met, I can then place an order (long or short depends on the direction that has been determined) with an entry, a target, and a trailing stop at the opening of the new bar.
However, there is a caveat. If the order is not filled within the next 2 bars, then I want the order to cancel. Also, if the order is filled and the target or the stop is not filled within the next 4 bars, then I want to exit the trade at market.
I also want the trailing stop to trail after it has moved into the profitable territory a bit, so that at minimum it makes a 1-tick profit and continues trailing as certain percentages of profit has reached.
Thank you
Can you help answer these questions from other members on NexusFi?
you can store the bar number when you send the orders and then cancel the orders after X bars. As a hint, the order will be cancelled when a condition for the order is not present anymore.
The same can be done for exiting the trade at market. Store the bar number of your entry and after Y bars send a market order to close your position.
By the way, for closing a position you can also use PosTradeEntryBar(), which you then only need to subtract from the current bar number ( Symbol_CurrentBar).
Can you share your code (attempt) till now? That way we can give more focused feedback and then you'll learn the most, as opposed to being given a copy/paste solution.
I agree with Jura, posting your code attempt and using feedback to improve it will in the end help you much more in climbing the next step up from being a "moderate Easy Language coder".
PosTradeEntryBar will only work in Multicharts though, for Tradestation you'd have to use OOEL and this requires a bit more advanced skills. You can however use BarsSinceEntry() and it should work fine when not dealing with multi leg entries.
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1
Thank you ABCTG & Jura. I wrote some simple code to get the order execution portion of the coding running correctly. Here is how far I've gotten so far and I haven't been successful at the order execution portion of the coding yet! I haven't even gotten into canceling an order yet either.
you place your stop and target reserved words inside conditional checks. This means these will only be active when the conditions are true, too. Whenever your conditions are false you'd be left without a stop and target.
Please elaborate what the exact issues are that you are seeing with your code.
Platform: NinjaTrader, TadeStation, ThinkOrSwim, and StreetSmartEdge
Trading: CL
Posts: 9 since Aug 2015
Thanks Given: 11
Thanks Received: 1
ABCTG
DrRon,
you place your stop and target reserved words inside conditional checks. This means these will only be active when the conditions are true, too. Whenever your conditions are false you'd be left without a stop and target.
Please elaborate what the exact issues are that you are seeing with your code.
Regards,
ABCTG
Thank you ABCTG. I cleaned up my code a bit more as shown below:
If BarStatus(1)=2 And Range>=Min_Range And Range<=Max_Range Then
Begin
Bull=Open<Close;
Bear=Open>Close;
If MarketPosition(0)=0 Then
Begin
If Bullish=1 And Bull
Then
Begin
Buy Numb_Shares Shares Next Bar At High Stop;
SetStopShare;
BuyTarget=(Range*x);
BuyStop=Range-(Range*x);
SetProfitTarget(BuyTarget);
SetStopLoss(BuyStop);
Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bullish",High,BuyTarget,BuyStop);
End
Else
If Bearish=1 And Bear
Then
Begin
SellShort Numb_Shares Shares Next Bar At Low Stop;
SetStopShare;
SellTarget=(Range*x);
SellStop=Range-(Range*x);
SetProfitTarget(SellTarget);
SetStopLoss(SellStop);
Print(File("c:\testOrderExe.txt"),Date,Time,Close,"Bearish",Low,SellTarget,SellStop);
End;
End;
End;
I want to be able to enter a trade when the conditions, noted above, are met and at the same time, my target and stop are set once and only once until the trade is complete. Ultimately, also, if my order is not filled, I also want to be able to cancel that order, if the price goes past the Stop first before coming back to fill me!
Right now, what happens is that only two trades are taken place a few bars apart. No further trades before or after these two trades take place, even though the conditions are appropriate for more order entries.