Support Board
Date/Time: Sun, 02 Feb 2025 12:57:26 +0000
Post From: Code Correction help (Aim is to avoid consecutive buy/sell signals)
[2019-09-02 10:37:38] |
rvdesh - Posts: 28 |
/* Please help rectify the error in the code*/ #include "sierrachart.h" /************************************************************/ SCDLLName("Gap Open Study") SCSFExport scsf_GapOpenStudy(SCStudyInterfaceRef sc) { SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0]; SCSubgraphRef SellEntrySubgraph = sc.Subgraph[2]; SCInputRef Enabled = sc.Input[0]; if (sc.SetDefaults) { // Set the study configuration and defaults. sc.GraphName = "Gap Open Delay Study"; sc.StudyDescription = "Signals based on Gap"; sc.GraphRegion = 0; BuyEntrySubgraph.Name = "Buy Entry"; BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_UP; BuyEntrySubgraph.PrimaryColor = RGB(0, 255, 0); BuyEntrySubgraph.LineWidth = 2; BuyEntrySubgraph.DrawZeros = false; SellEntrySubgraph.Name = "Sell Entry"; SellEntrySubgraph.DrawStyle = DRAWSTYLE_ARROW_DOWN; SellEntrySubgraph.PrimaryColor = RGB(255, 0, 0); SellEntrySubgraph.LineWidth = 2; SellEntrySubgraph.DrawZeros = false; Enabled.Name = "Enabled"; Enabled.SetYesNo(1); sc.AutoLoop = 1; sc.GraphRegion = 0; return; } float OpenValue = sc.Open[sc.Index - 1]; float CloseValue = sc.Close[sc.Index - 1]; float PrevLowValue = sc.Low[sc.Index - 2]; float PrevHighValue = sc.High[sc.Index - 2]; bool up = OpenValue < PrevLowValue; bool dn = OpenValue > PrevHighValue; /*The next two lines compile but there are too many up/down signals, causing whipsaws. */ bool buysignal = up && !dn[sc.Index - 1]; bool sellsignal = dn && !up[sc.Index - 1]; /*To avoid whipsaws I want buysignal to be true only if open < previous low and there is no sellsignal on the previous bar. Similarly , I want sellsignal to be true only if Open > Previous High and there is no buysignal on the previous bar But the code is not building but returning error. bool buysignal = up && !dn[sc.Index - 1]; bool sellsignal = dn && !up[sc.Index - 1];*/ if (buysignal == true) { BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index]; } else if (sellsignal == true) { SellEntrySubgraph[sc.Index] = sc.High[sc.Index]; } } //Please rectify error and help Date Time Of Last Edit: 2019-09-02 10:39:26
|