R1: 12967.3333333333 R2: 13044.4166666667 Close: 3867.5
S1: 12770.5833333333 S2: 12650.9166666667 Close: 3867.5
its getting the close from the secondary but the R1 and 2 , S1 and 2 are still coming from the primary
how do i fix this ?
below is pieces of the code
else if (State == State.Configure)
{
// set up Pivots indicator
Pivots1 = Pivots(Close, PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20); // using daily bars
// set up RSI indicator
rsi = RSI(RSIPeriod, 3);
// Setup ATR INdicator
atr = ATR(ATRperiod);
AddDataSeries(secondaryInstrumentSymbol,secondaryI nstrumentPeriod);
AddDataSeries("ES ##-##", Data.BarsPeriodType.Minute, 1);
if (ShowIndicators == 1)
{
// Add the indicators to the chart only if ShowIndicators is set to 1
AddChartIndicator(Pivots1);
AddChartIndicator(rsi);
AddChartIndicator(atr);
}
}
else if (State == State.DataLoaded)
{
if (BarsArray[0].Count < 20 || BarsArray[1].Count < 20)
{
// Not enough data to start the strategy, exit or throw an exception
return;
}
// Create a new instance of Pivots and set its Input property
Pivots2 = Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20);
Pivots2.SetInput(BarsArray[1]);
AddChartIndicator(Pivots2);
// Wait for all indicators to be initialized
if (Pivots1.State != State.Historical ||Pivots2.State != State.Historical || rsi.State != State.Historical || atr.State != State.Historical)
return;
}
private void ManageHedgeEntry()
{
Print("ManageHedgeEntry called"); // Add this line
Print("MarketPosition: " + Position.MarketPosition);
if (OkToTrade && Position.MarketPosition != MarketPosition.Flat) // Added condition to check if primary position is active
{
if (Position.MarketPosition == MarketPosition.Long)
{
Print("In Long position");
Print("R1: " + Pivots2.R1[0] + " R2: " + Pivots2.R2[0] + " Close: " + BarsArray[1].GetClose(0));
// Add more print statements for the conditions
Print("Condition R1: " + (BarsArray[1].GetClose(0) <= Pivots2.R1[0]));
Print("Condition R2: " + (BarsArray[1].GetClose(0) <= Pivots2.R2[0]));
Print("Checking hedge entry conditions for Long position"); // Added debug message
// Hedge entry conditions for long primary position
if (BarsArray[1].GetClose(0) <= Pivots2.R1[0])
{
double hedgeShortLimitPrice = Pivots2.R1[0] ;
hedgeShort1Order = EnterShortLimit(1, true, 1, hedgeShortLimitPrice, @"HedgeShort1");
Print("Entered HedgeShort1"); // Added debug message
}
if (BarsArray[1].GetClose(0) <= Pivots2.R2[0])
{
double hedgeShortLimitPrice = Pivots2.R1[0];
hedgeShort2Order = EnterShortLimit(1, true, 1, hedgeShortLimitPrice, @"HedgeShort2");
Print("Entered HedgeShort2"); // Added debug message
}
}
else if (Position.MarketPosition == MarketPosition.Short)
{
Print("In Short position");
Print("S1: " + Pivots2.S1[0] + " S2: " + Pivots2.S2[0] + " Close: " + BarsArray[1].GetClose(0));
// Add more print statements for the conditions
Print("Condition S1: " + (BarsArray[1].GetClose(0) >= Pivots2.S1[0]));
Print("Condition S2: " + (BarsArray[1].GetClose(0) >= Pivots2.S2[0]));
if (BarsArray[1].GetClose(0) >= Pivots2.S1[0])
{
double hedgeLongLimitPrice = Pivots2.S1[0] ;
hedgeLong1Order = EnterLongLimit(1, true, 1, hedgeLongLimitPrice, @"HedgeLong1");
Print("Entered HedgeLong1"); // Added debug message
}
if (BarsArray[1].GetClose(0) >= Pivots2.S2[0])
{
double hedgeLongLimitPrice = Pivots2.S2[0];
hedgeLong2Order = EnterLongLimit(1, true, 1, hedgeLongLimitPrice, @"HedgeLong2");
Print("Entered HedgeLong2"); // Added debug message
}
}
}
}

Comment