Support Board
Date/Time: Mon, 20 Jan 2025 16:48:32 +0000
Post From: Please Help: Study Overlay not working correctly in Live Trading
[2018-06-19 01:36:14] |
rahul - Posts: 167 |
Hello, I am currently using Study Overlay to do a Moving Average Crossover. The source chart is a 60 minute chart and destination chart is a 10 minute chart. What I want is that when the moving average crosses over on 60 minute chart, I should trade based on 10 minute chart. The logic is as soon as the moving average crossover happens on the 60 minute chart, I should be able to trade on the 10 minute chart on the bar close of the 10 minute chart. The code works fine when I back-test the data. However on live trading the trade is only automatically executed when 60 minute bar closes. So if the crossover happens at 10:13 AM for example, the trade should execute on 10 minute bar close at 10:20 AM. This works fine in back-testing. However in live trading the trade executed at 11:00 AM instead, which is the 60 minute bar close. Not sure why this is happening. The chart order: Chart 1: 60 minute chart Chart 2: 10 minute chart Study Overlay Study on 10 minute chart referencing 60 minute chart. Then I am referencing the moving averages through my code from the Study Overlay. The following code has been added to my coded study: sc.CalculationPrecedence = LOW_PREC_LEVEL sc.GetStudyArrayUsingID(Input_ID1.GetStudyID(), Input_ID1.GetSubgraphIndex(), Arr_ID1); sc.GetStudyArrayUsingID(Input_ID2.GetStudyID(), Input_ID2.GetSubgraphIndex(), Arr_ID2); Output_ID1[cB] = Arr_ID1[cB]; Output_ID2[cB] = Arr_ID2[cB]; An example of Buy Entry Condition on the 10 minute chart: (Output_ID1 => Moving Average 1 and Output_ID2 => Moving Average 2) if ((Output_ID1[sc.Index - 1] < Output_ID2[sc.Index - 1]) && (Output_ID1[sc.Index] > Output_ID2[sc.Index]) && (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED)) BuyToOpen = 1; s_SCPositionData PositionData; sc.GetTradePosition(PositionData); if ((BuyToOpen == 1) && (PositionData.PositionQuantity == 0)) sc.BuyEntry(NewOrder); Not sure why the behavior in back-testing is done correctly and not working in Live Trading (CQG WebAPI). Please help! Date Time Of Last Edit: 2018-06-22 12:14:41
|