Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Entry after ProfitTarget
Collapse
X
-
Hello,
Thank you for the reply.
Based on your reply it sounds like the condition can remain true, but you only want to enter when it initially becomes true once. After you enter, exit and it is still true, do not enter again unless it is becomes no longer true and then becomes true again.
Based on your sample, this could prove difficult because you are using CalculateOnBarClose = false depending on what exactly you are trying to do.
I wanted to check with you, should this be able to allow another trade on the same bar or are you looking to avoid trading on the same bar all together?
If you want to trade only after this bar, it may be easier to use BarsSinceExit. Otherwise if you would like to still allow another entry on the same bar but only after the condition becomes true again, that could proove more difficult and would require more logic.
Can you confirm which case you are trying to achieve?
I look forward to being of further assistance.
-
Jesse, I made the changes to the code and removed the SetStopLoss from Initailize.
I need help with the following: I do not want to re enter the trade when StopLoss, ProfitTarget or ExitLong (ExitShort) based on Condition AB (or Condition CD) have been triggered even if Condition AB (or Condtion CD) continues to be true. The strategy only trades again after Condition AB/CD becomes true again after being false.
So using your assumption:
Position is flat so a StopLoss is preset.
Condition becomes true and trade is entered and StopLoss, ProfitTarget or Exit is triggered. This will be the only trade even if the condition remains true. Strategy will trade again the next time the condition goes to true.
Thanks again.
Code:protected override void Initialize() { SetProfitTarget(CalculationMode.Ticks,MyTarget); CalculateOnBarClose = false; } protected override void OnBarUpdate() { if ( ToTime(Time[0]) >= 151000 && Position.MarketPosition != MarketPosition.Flat) //Exit all positions by 3:10 pm { if ( Position.MarketPosition == MarketPosition.Long ) { ExitLong(); } else { ExitShort(); } } if(ToTime(Time[0]) >= 83000 && ToTime(Time[0]) < 151000) //Only trade between 8:30 am to 3:10 pm { if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks,MyStop); if (BarsSinceExit()!=0 && Condition AB) { EnterLong(); } } if (Position.MarketPosition == MarketPosition.Long) { if(Condition 1) { ExitLong(); } else if(Condition 2) { ExitLong(); } } if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks,MyStop); if (BarsSinceExit()!=0 && Condition CD) { EnterShort(); } } if (Position.MarketPosition == MarketPosition.Short) { if(Condition 3) { ExitShort(); } else if(Condition 4) { ExitShort(); } } } }
Leave a comment:
-
Hello,
Originally posted by 2Look4me View Post
I would like to close that trade once StopLoss or ProfitTarget is hit even if condition 1 remains true. Then re enter once Condition 1 becomes true again.
Walking through the logic you have provided:
You are flat so a stop is preset
Condition becomes true and trade is entered and stoploss is set
The stop gets filled and the strategy immediately trades again.
Is this correct?
I also have noticed you are using both Initialize and OnBarUpdate to set the stop, this can cause conflicts I would suggest removing it from Initialize and just SetStopLoss where you need in OnBarUpdate prior to submitting the order.
Can you provide further details on what you are seeing as this was only a small sample of syntax?
Is this happening on the same bar and you want to prevent the entry from entering on the same bar twice? or is this an entry on the next bar or after?
The information in post 2 would be relevant if you are trying to stop intrabar multiple entries or if you wanted to specify that an entry has to be X number of bars after the exit.
I look forward to being of further assistance.
Leave a comment:
-
Thanks Jesse/Koganam for the help.
I would like to close that trade once StopLoss or ProfitTarget is hit even if condition 1 remains true. Then re enter once Condition 1 becomes true again.
Leave a comment:
-
Originally posted by 2Look4me View PostHi,
Just started on how to implement strategies and have SetStopLoss and SetProfitTarget. The problem I'm running into, is that once the Profit Target is hit, it will also immediately EnterLong again. Thanks in advance.
Code:Protected override void Initialize() { SetStopLoss(CalculateMode.Ticks, MyStop); SetProfitTarget(CalculateMode.Ticks, MyTarget); } protected override void OnBarUpdate() { if(Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculateMode.Ticks,MyStop); } if(Condition 1) { EnterLong(); }
Leave a comment:
-
Hello,
Thank you for the question.
It seems your Condition could remain true during the exit which would allow for it to enter again after exiting.
BarsSinceExit may be of use in your condition: http://ninjatrader.com/support/helpG...=barssinceexit
This has 3 states, -1, 0 and > 0 which means it could be used with initial entry logic before there is an exit.
You could check
Code:if(BarsSinceExit() != 0)
I look forward to being of further assistance.
Leave a comment:
-
Entry after ProfitTarget
Hi,
Just started on how to implement strategies and have SetStopLoss and SetProfitTarget. The problem I'm running into, is that once the Profit Target is hit, it will also immediately EnterLong again. Thanks in advance.
Code:Protected override void Initialize() { SetStopLoss(CalculateMode.Ticks, MyStop); SetProfitTarget(CalculateMode.Ticks, MyTarget); } protected override void OnBarUpdate() { if(Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculateMode.Ticks,MyStop); } if(Condition 1) { EnterLong(); }
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
14 responses
1,788 views
0 likes
|
Last Post
by aligator
Today, 11:47 AM
|
||
Started by Jimmyk, 01-26-2018, 05:19 AM
|
6 responses
837 views
0 likes
|
Last Post
by emuns
Today, 11:27 AM
|
||
Started by jxs_xrj, 01-12-2020, 09:49 AM
|
6 responses
3,293 views
1 like
|
Last Post
by jgualdronc
Today, 10:56 AM
|
||
Started by Touch-Ups, Today, 10:36 AM
|
0 responses
13 views
0 likes
|
Last Post
by Touch-Ups
Today, 10:36 AM
|
||
Started by geddyisodin, 04-25-2024, 05:20 AM
|
11 responses
63 views
0 likes
|
Last Post Today, 10:08 AM |
Leave a comment: