NexusFi: Find Your Edge


Home Menu

 





disabling strategy after closed trade


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one cutzpr with 1 posts (1 thanks)
    2. looks_two xplorer with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 sra18376 with 1 posts (0 thanks)
    1. trending_up 891 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

disabling strategy after closed trade

  #1 (permalink)
sra18376
kansas city, ks
 
Posts: 17 since Jun 2014
Thanks Given: 0
Thanks Received: 5

I am building a strategy and would like for it to automatically 'disable' after a trade is closed.

essentially, i would like to have it set up where i pick a stock, start the strategy on it (starting the strategy immediately opens a long or short), and then when the parameters are met to close the trade, the trade is closed and the strategy stops.

I have achieved this thus far by having a bool flip on when i exit a long or short that prevents me from automatically entering another trade.

However when testing applying the strategy on a chart, it never stays enabled because the strategy starts on past candles on the chart instead of the current one and closes the trade before the current candle starts. this causes the bool to flip on before my current trade is able to even play out.

Is there a better way to achieve what i am trying to do? Or, is there a way to have the strategy not be applied to any of the prior data in a chart?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
80 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Tao te Trade: way of the WLD
46 thanks
Just another trading journal: PA, Wyckoff & Trends
35 thanks
The Program
19 thanks
  #3 (permalink)
 
xplorer's Avatar
 xplorer 
London UK
Site Moderator
 
Experience: Beginner
Platform: CQG
Broker: S5
Trading: Futures
Posts: 5,980 since Sep 2015
Thanks Given: 15,506
Thanks Received: 15,420



sra18376 View Post
I am building a strategy and would like for it to automatically 'disable' after a trade is closed.

essentially, i would like to have it set up where i pick a stock, start the strategy on it (starting the strategy immediately opens a long or short), and then when the parameters are met to close the trade, the trade is closed and the strategy stops.

I have achieved this thus far by having a bool flip on when i exit a long or short that prevents me from automatically entering another trade.

However when testing applying the strategy on a chart, it never stays enabled because the strategy starts on past candles on the chart instead of the current one and closes the trade before the current candle starts. this causes the bool to flip on before my current trade is able to even play out.

Is there a better way to achieve what i am trying to do? Or, is there a way to have the strategy not be applied to any of the prior data in a chart?

You could add a condition the checks whether the PnL is different from zero.

Reply With Quote
  #4 (permalink)
 
cutzpr's Avatar
 cutzpr 
United States
 
Experience: None
Platform: TWS,Ninja Trader
Trading: Forex, Futures, Stocks
Posts: 35 since Apr 2012
Thanks Given: 10
Thanks Received: 10

You would want to do something like this.
 
Code
                            


if(State == State.Historical) return; //It will not continue if bars are historical, only realtime

If(SignalEnter)
{
enter market
}

if(
SignalExit)
{
exit 
market // exit market
foreach (Order o in Orders// Cancel all pending orders 
{
Cancel(o);
}
CloseStrategy() // Close and exit Strategy


Reply With Quote
Thanked by:




Last Updated on January 7, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts