Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Continously Update Long Position Until Its The Absolute Bottom In The Trendline

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Continously Update Long Position Until Its The Absolute Bottom In The Trendline

    So this strategy is entirley meant to be just for historical data and what not, not meant to be traded real time, ideally what I am trying to do is buy at the bottom of every support line for a given trend, here is a picture of what it currently does:

    Click image for larger version

Name:	asd.PNG
Views:	201
Size:	36.1 KB
ID:	1173891
    So the red is where I need to be long and then just close say 2 points after, I have this for the most part but the stop loss is generally my problem now. I basically need to enter a position with say a 2 tick stop loss, if it hits the stop loss then it wasnt the "absolute bottom", thus I re enter the trade and sit another 2 tick stop loss, this occurs until it goes back up and hits the take profit. Currently I use Bollinger bands to measure the trend, here is my current code:
    Code:
     public class LabeledDataStrategy : Strategy
    {
    private Bollinger Bollinger20;
    private int totalContracts = 1;
    private int counter = 0;
    public double ConvertToEpochTimestamp(DateTime dateTime)
    {
    DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    TimeSpan diff = dateTime.ToUniversalTime() - origin;
    return Math.Floor(diff.TotalSeconds);
    }
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"LabeledDataStrategy";
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    Calculate = Calculate.OnEachTick;
    BarsRequiredToPlot = 15;
    Name = "LabeledDataStrategy";
    period = 5;
    stopLoss = .5;
    
    }
    }
    
    protected override void OnBarUpdate()
    {
    if(counter == 0)
    {
    counter++;
    }
    
    if (Position.MarketPosition == MarketPosition.Long)
    {
    if (Close[0] >= Position.AveragePrice + 8 * TickSize)
    {
    ExitLong("LONG");
    }
    }
    double lower = Bollinger(2, period).Lower[0];
    
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if (Close[0] - lower <= .5 || Low[0] <= lower)
    {
    EnterLong(totalContracts, "LONG");
    SetStopLoss(CalculationMode.Ticks, 1);
    }
    }
    }
    
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name = "period", Order = 1, GroupName = "Parameters")]
    public int period
    { get; set; }
    
    
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name = "stopLoss", Order = 1, GroupName = "Parameters")]
    public double stopLoss
    { get; set; }
    
    
    
    }
    What is the best way to achieve this, basically if(stopped out){ buy in with stop loss again}. To reiterate this is not for live trading nor is this for probability or profit, just historical data related, any help would be appreciated!


    #2
    Hello laner107,

    Our support team is not able to write the logic on your behalf but we can help you to use prints to understand why the behavior is not as you expect.

    What is the current behavior that is unexpected that has you stuck?

    Is the entry being placed at the correct time and place?

    One note, set methods should be called before the entry is submitted.

    SetStopLoss(CalculationMode.Ticks, 1);
    EnterLong(totalContracts, "LONG");

    With the stop, this being submitted 1 tick from the entry price is highly likely to fill instantly, is this the behavior that is unexpected?

    Are you having trouble submitting a new entry when the stop loss is filled?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wisdomspoon, Today, 03:50 PM
    3 responses
    14 views
    0 likes
    Last Post rockmanx00  
    Started by Mountain_cast, 02-10-2025, 11:14 PM
    2 responses
    19 views
    0 likes
    Last Post Mountain_cast  
    Started by Robotman, Today, 01:06 PM
    2 responses
    37 views
    0 likes
    Last Post Robotman  
    Started by PH_GMT, Today, 12:40 PM
    4 responses
    19 views
    0 likes
    Last Post PH_GMT
    by PH_GMT
     
    Started by 80grit, 01-11-2025, 10:57 AM
    13 responses
    285 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Working...
    X