- ago
Basically I want to weight this strategy by RSI in pre execution and then reduce amount of signals down to lowest 6 BUT after the below indicators have generated their signals if statements below have been ran? I have been unsuccessful in creating a buy list in the pre-execute after indicators have generated their signals BUT before the Buy and sell. Is there a way to move those statements to have multiple statements in the pre-execute area?

Can I add this statement into the pre-execute area and then weighted by RSI to reduce to only 6 signals into the buy list?

CODE:
if (index - Parameters[5].AsInt >= 0 && (indicator1[index] < indicator2[index - Parameters[5].AsInt] * (1.0 - (Parameters[4].AsDouble / 100.0))))



CODE:
   public override void PreExecute(DateTime dt, List<BarHistory> participants)       {          // rank the candidates by rsi          foreach (BarHistory bh in participants)          {             RSI symbolRsi = (RSI)bh.Cache[seriesKey];             int idx = GetCurrentIndex(bh); //this returns the index of the BarHistory for the bar currently being processed             double rsiVal = symbolRsi[idx];                bh.UserData = rsiVal; //save the current AvgROC value along with the BarHistory instance          }          //sort the participants by AvgROC value (lowest to highest)          participants.Sort((a, b) => a.UserDataAsDouble.CompareTo(b.UserDataAsDouble));          //keep the top 3 symbols          buys.Clear();          for (int n = 0; n < 12; n++)          {             if (n >= participants.Count)                break;             buys.Add(participants[n]);          }       }
0
614
Solved
2 Replies

Reply

Bookmark

Sort
Cone8
 ( 6.71% )
- ago
#1
CODE:
//create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          bars.Cache["Ind1"] = new SMA(bars.Close, 20);   // whatever the indicators are          bars.Cache["Ind2"] = new SMA(bars.Close, 40); }       public override void PreExecute(DateTime dt, List<BarHistory> participants)       {          // rank the candidates by rsi          foreach (BarHistory bh in participants)          {             RSI symbolRsi = (RSI)bh.Cache[seriesKey];             int idx = GetCurrentIndex(bh); //this returns the index of the BarHistory for the bar currently being processed             double rsiVal = symbolRsi[idx];             bh.UserData = rsiVal; //save the current AvgROC value along with the BarHistory instance          }          //sort the participants by AvgROC value (lowest to highest)          participants.Sort((a, b) => a.UserDataAsDouble.CompareTo(b.UserDataAsDouble));          //keep the top symbols          buys.Clear();          for (int n = 0; n < 12; n++)          {             if (n >= participants.Count)                break;             buys.Add(participants[n]);          }          for (int n = buys.Count - 1; n >= 0; n--)          {             BarHistory bars = buys[n];             int idx = GetCurrentIndex(bars);             TimeSeries indicator1 = (TimeSeries)bars.Cache["Ind1"];             TimeSeries indicator2 = (TimeSeries)bars.Cache["Ind2"];             bool keep = (idx - Parameters[5].AsInt >= 0 && (indicator1[idx] < indicator2[idx - Parameters[5].AsInt] * (1.0 - (Parameters[4].AsDouble / 100.0))));             if (!keep)             {                buys.Remove(bars);             }          }       }


0
Best Answer
- ago
#2
Thank you! I spent 6 hours last night trying to code this and I never got the results to match up! I GREATLY appreciate your help!
1

Reply

Bookmark

Sort