Support Board
Date/Time: Wed, 25 Dec 2024 05:27:09 +0000
Post From: Delta Divergence Source Code -- Does Not Compile
[2015-11-06 12:19:48] |
KhaosTrader - Posts: 128 |
Please also note I tried to compile the latest version (version 5) which does not compile.. The Latest Version 5 Source is here: /* jdt Delta Divergence Author: jsyd Date: 11/13/2011 */ #include "sierrachart.h" #include <string> SCDLLInit("Delta Divergence"); /***********************************************************************/ SCSFExport scsf_DeltaDivergence(SCStudyGraphRef sc) { SCSubgraphRef ddVolSubgraph = sc.Subgraph[0]; SCSubgraphRef ddBuySubgraph = sc.Subgraph[1]; SCSubgraphRef buyPriceSubgraph = sc.Subgraph[2]; SCSubgraphRef ddSellSubgraph = sc.Subgraph[3]; SCSubgraphRef sellPriceSubgraph = sc.Subgraph[4]; SCSubgraphRef ma1Subgraph = sc.Subgraph[5]; SCSubgraphRef ma2Subgraph = sc.Subgraph[6]; SCSubgraphRef tSetupSubgraph = sc.Subgraph[7]; SCSubgraphRef stSubgraph = sc.Subgraph[8]; SCSubgraphRef btSubgraph = sc.Subgraph[9]; SCSubgraphRef sslSubgraph = sc.Subgraph[10]; SCSubgraphRef bslSubgraph = sc.Subgraph[11]; SCSubgraphRef lossCntSubgraph = sc.Subgraph[12]; SCSubgraphRef winCntSubgraph = sc.Subgraph[13]; SCSubgraphRef lossPLSubgraph = sc.Subgraph[14]; SCSubgraphRef winPLSubgraph = sc.Subgraph[15]; SCSubgraphRef test = sc.Subgraph[16]; SCInputRef version = sc.Input[0]; SCInputRef useCumVolInput = sc.Input[1]; SCInputRef volTypeInput = sc.Input[2]; SCInputRef ddModeInput = sc.Input[3]; SCInputRef useCSTInput = sc.Input[4]; SCInputRef ddPeriodInput = sc.Input[5]; SCInputRef ma1Input = sc.Input[6]; SCInputRef ma2Input = sc.Input[7]; SCInputRef maTypeInput = sc.Input[8]; SCInputRef maInputDataInput = sc.Input[9]; SCInputRef ddOffsetInput = sc.Input[10]; SCInputRef maZoneInput = sc.Input[11]; SCInputRef sigZoneInput = sc.Input[12]; SCInputRef tradeModeInput = sc.Input[13]; SCInputRef tPriceInput = sc.Input[14]; if(sc.SetDefaults) { sc.GraphName="Delta Divergence"; sc.StudyDescription="Delta Divergence with option to only trade with trend"; ddVolSubgraph.Name = "Delta Volume"; ddVolSubgraph.DrawStyle = DRAWSTYLE_DONOTDRAW; ddBuySubgraph.Name = "Delta Divergence Buy"; ddBuySubgraph.DrawStyle = DRAWSTYLE_ARROWUP; ddBuySubgraph.PrimaryColor = RGB(0, 255, 0); ddBuySubgraph.LineWidth = 2; buyPriceSubgraph.Name = "Buy Price"; buyPriceSubgraph.DrawStyle = DRAWSTYLE_DASH; buyPriceSubgraph.PrimaryColor = RGB(128,255,128); buyPriceSubgraph.LineWidth = 4; ddSellSubgraph.Name = "Delta Divergence Sell"; ddSellSubgraph.DrawStyle = DRAWSTYLE_ARROWDOWN; ddSellSubgraph.PrimaryColor = RGB(255, 0, 0); ddSellSubgraph.LineWidth = 2; sellPriceSubgraph.Name = "Sell Price"; sellPriceSubgraph.DrawStyle = DRAWSTYLE_DASH; sellPriceSubgraph.PrimaryColor = RGB(255,128,128); sellPriceSubgraph.LineWidth = 4; stSubgraph.Name = "Sell Target Price"; stSubgraph.DrawStyle = DRAWSTYLE_DASH; stSubgraph.PrimaryColor = RGB(255,255,255); stSubgraph.LineWidth = 4; btSubgraph.Name = "BuyTarget Price"; btSubgraph.DrawStyle = DRAWSTYLE_DASH; btSubgraph.PrimaryColor = RGB(255,255,255); btSubgraph.LineWidth = 4; sslSubgraph.Name = "Sell StopLoss Price"; sslSubgraph.DrawStyle = DRAWSTYLE_DASH; sslSubgraph.PrimaryColor = RGB(255,0,0); sslSubgraph.LineWidth = 4; bslSubgraph.Name = "Buy StopLoss Price"; bslSubgraph.DrawStyle = DRAWSTYLE_DASH; bslSubgraph.PrimaryColor = RGB(255,0,0); bslSubgraph.LineWidth = 4; ma1Subgraph.Name = "ma1"; ma1Subgraph.DrawStyle = DRAWSTYLE_LINE; ma1Subgraph.PrimaryColor = RGB(0, 128, 0); ma1Subgraph.SecondaryColor = RGB(0, 0, 0); ma1Subgraph.LineWidth = 1; ma2Subgraph.Name = "ma2"; ma2Subgraph.DrawStyle = DRAWSTYLE_LINE; ma2Subgraph.PrimaryColor = RGB(128, 0, 0); ma2Subgraph.SecondaryColor = RGB(0, 0, 0); ma2Subgraph.LineWidth = 1; tSetupSubgraph.Name = "Trade Setup Signal"; tSetupSubgraph.DrawStyle = DRAWSTYLE_DONOTDRAW; lossCntSubgraph.Name = "Loss Cnt Subgraph"; lossCntSubgraph.DrawStyle = DRAWSTYLE_DONOTDRAW; winCntSubgraph.Name = "Win Cnt Subgraph"; winCntSubgraph.DrawStyle = DRAWSTYLE_DONOTDRAW; lossPLSubgraph.Name = "Loss PL Subgraph"; lossPLSubgraph.DrawStyle = DRAWSTYLE_DONOTDRAW; winPLSubgraph.Name = "Win PL Subgraph"; winPLSubgraph.DrawStyle = DRAWSTYLE_DONOTDRAW; test.Name = "Test Subgraph"; test.DrawStyle = DRAWSTYLE_DONOTDRAW; // Inputs useCumVolInput.Name = "Use Cummulative Volume"; useCumVolInput.SetYesNo(true); volTypeInput.Name = "Volume Type - 1=Ask-Bid, 2=UpTickVol-DnTickVol"; volTypeInput.SetInt(1); volTypeInput.SetIntLimits(1, 2); ddModeInput.Name = "Trend following mode"; ddModeInput.SetYesNo(false); useCSTInput.Name = "Use Daily HH/LL (else define period)"; useCSTInput.SetYesNo(true); ddPeriodInput.Name = "Lookback Period"; ddPeriodInput.SetInt(13); ddPeriodInput.SetIntLimits(0, 1000); ma1Input.Name = "Fast MA Length"; ma1Input.SetInt(20); ma1Input.SetIntLimits(1, 10000); ma2Input.Name = "Slow MA Length"; ma2Input.SetInt(30); ma2Input.SetIntLimits(1, 10000); maTypeInput.Name = "MA Type"; maTypeInput.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL); maInputDataInput.Name = "MA Input Data"; maInputDataInput.SetInputDataIndex(SC_LAST); ddOffsetInput.Name = "Display Signal Offset"; ddOffsetInput.SetFloat(.001); ddOffsetInput.SetFloatLimits(.00001f, 1000); maZoneInput.Name = "MA Trend Zone"; maZoneInput.SetFloat(.0002); maZoneInput.SetFloatLimits(.00001f, 1000); sigZoneInput.Name = "Entry Signal Zone"; sigZoneInput.SetFloat(.0005); sigZoneInput.SetFloatLimits(.00001f, 1000); tradeModeInput.Name = "Trade Mode - signals when trigger bar is broken"; tradeModeInput.SetYesNo(true); tPriceInput.Name = "Target (ticks/pips)"; tPriceInput.SetFloat(.001); tPriceInput.SetFloatLimits(.00001f, 1000); version.Name = "Version"; version.SetInt(5); version.SetIntLimits(5,5); sc.DrawZeros = false; sc.AutoLoop = 1; sc.FreeDLL = 1; sc.GraphRegion = 0; sc.ValueFormat = 6; sc.ScaleRangeType=SCALE_SAMEASREGION; return; } int cur = sc.Index; int& inTrade = sc.PersistVars->i1; /*====================================================================================== MA ========================================================================================*/ sc.MovingAverage(sc.BaseDataIn[maInputDataInput.GetInputDataIndex()], ma1Subgraph, maTypeInput.GetMovAvgType() , cur, ma1Input.GetInt()); sc.MovingAverage(sc.BaseDataIn[maInputDataInput.GetInputDataIndex()], ma2Subgraph, maTypeInput.GetMovAvgType() , cur, ma2Input.GetInt()); /*==================================================================================== Delta Divergence ====================================================================================*/ if(tradeModeInput.BooleanValue) { lossCntSubgraph[cur] = lossCntSubgraph[cur-1]; winCntSubgraph[cur] = winCntSubgraph[cur-1]; lossPLSubgraph[cur] = lossPLSubgraph[cur-1]; winPLSubgraph[cur] = winPLSubgraph[cur-1]; if(inTrade == 1) { if(sc.BaseDataIn[SC_LOW][cur] <= bslSubgraph[cur-1]) { inTrade = 0; lossPLSubgraph[cur] = (bslSubgraph[cur-1] - buyPriceSubgraph[cur-1]) + lossPLSubgraph[cur]; buyPriceSubgraph[cur] = 0; btSubgraph[cur] = 0; bslSubgraph[cur] = 0; lossCntSubgraph[cur] = lossCntSubgraph[cur] + 1; } else if(sc.BaseDataIn[SC_HIGH][cur] > btSubgraph[cur-1]) { inTrade = 0; winPLSubgraph[cur] = (btSubgraph[cur-1] - buyPriceSubgraph[cur-1]) + winPLSubgraph[cur]; buyPriceSubgraph[cur] = 0; btSubgraph[cur] = 0; bslSubgraph[cur] = 0; winCntSubgraph[cur] = winCntSubgraph[cur] + 1; } else { buyPriceSubgraph[cur] = buyPriceSubgraph[cur-1]; btSubgraph[cur] = btSubgraph[cur-1]; bslSubgraph[cur] = bslSubgraph[cur-1]; } } else if(inTrade == -1) { if(sc.BaseDataIn[SC_HIGH][cur] >= sslSubgraph[cur-1]) { inTrade = 0; lossPLSubgraph[cur] = (sellPriceSubgraph[cur-1] - sslSubgraph[cur-1]) + lossPLSubgraph[cur]; sellPriceSubgraph[cur] = 0; stSubgraph[cur] = 0; sslSubgraph[cur] = 0; lossCntSubgraph[cur] = lossCntSubgraph[cur] + 1; } else if(sc.BaseDataIn[SC_LOW][cur] < stSubgraph[cur-1]) { inTrade = 0; winPLSubgraph[cur] = (sellPriceSubgraph[cur-1] - stSubgraph[cur-1]) + winPLSubgraph[cur]; sellPriceSubgraph[cur] = 0; stSubgraph[cur] = 0; sslSubgraph[cur] = 0; winCntSubgraph[cur] = winCntSubgraph[cur] + 1; } else { sellPriceSubgraph[cur] = sellPriceSubgraph[cur-1]; stSubgraph[cur] = stSubgraph[cur-1]; sslSubgraph[cur] = sslSubgraph[cur-1]; } } if((tSetupSubgraph[cur-1] == 1) && (sc.BaseDataIn[SC_HIGH][cur] > sc.BaseDataIn[SC_HIGH][cur-1] )) { ddBuySubgraph[cur] = sc.BaseDataIn[SC_LOW][cur] - ddOffsetInput.GetFloat(); if(inTrade == 0) { buyPriceSubgraph[cur] = sc.BaseDataIn[SC_HIGH][cur-1]; btSubgraph[cur] = buyPriceSubgraph[cur] + tPriceInput.GetFloat(); bslSubgraph[cur] = sc.BaseDataIn[SC_LOW][cur-1]; inTrade = 1; } } else if((tSetupSubgraph[cur-1] == -1) && (sc.BaseDataIn[SC_LOW][cur] < sc.BaseDataIn[SC_LOW][cur-1] )) { ddSellSubgraph[cur] = sc.BaseDataIn[SC_HIGH][cur] + ddOffsetInput.GetFloat(); if(inTrade == 0) { sellPriceSubgraph[cur] = sc.BaseDataIn[SC_LOW][cur-1]; stSubgraph[cur] = sellPriceSubgraph[cur] - tPriceInput.GetFloat(); sslSubgraph[cur] = sc.BaseDataIn[SC_HIGH][cur-1]; inTrade = -1; } } } if(sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) { float ddHigh; float ddLow; float Open; float Close; int uVolType = SC_ASKVOL; int dVolType = SC_BIDVOL; if(volTypeInput.GetInt() == 2) { uVolType = SC_UPVOL; dVolType = SC_DOWNVOL; } // ddVolSubgraph[cur] = sc.BaseDataIn[SC_ASKVOL][cur] - sc.BaseDataIn[SC_BIDVOL][cur]; if(useCSTInput.BooleanValue) { if(useCumVolInput.BooleanValue) { if(sc.SecondsSinceStartTime(sc.BaseDateTimeIn[cur]) < 30) { ddVolSubgraph[cur] = sc.BaseDataIn[uVolType][cur] - sc.BaseDataIn[dVolType][cur]; } else { ddVolSubgraph[cur] = ddVolSubgraph[cur-1] + (sc.BaseDataIn[uVolType][cur] - sc.BaseDataIn[dVolType][cur]); } } else { ddVolSubgraph[cur] = sc.BaseDataIn[uVolType][cur] - sc.BaseDataIn[dVolType][cur]; } sc.GetOHLCForDate(sc.BaseDateTimeIn[cur], Open, ddHigh, ddLow, Close); } else { if(useCumVolInput.BooleanValue) { for(int x=cur-ddPeriodInput.GetInt();x<=cur;x++) { if(x == cur-ddPeriodInput.GetInt()) { ddVolSubgraph[x] = sc.BaseDataIn[uVolType][x] - sc.BaseDataIn[dVolType][x]; } else { ddVolSubgraph[x] = ddVolSubgraph[x-1] + (sc.BaseDataIn[uVolType][x] - sc.BaseDataIn[dVolType][x]); } } } else { ddVolSubgraph[cur] = sc.BaseDataIn[uVolType][cur] - sc.BaseDataIn[dVolType][cur]; } ddHigh = sc.GetHighest(sc.BaseData[SC_HIGH], ddPeriodInput.GetInt()); ddLow = sc.GetLowest(sc.BaseData[SC_LOW], ddPeriodInput.GetInt()); } if(ddModeInput.BooleanValue) { if((ddVolSubgraph[cur] > 0) && (sc.BaseData[SC_LOW][cur] <= ddLow) && (ma1Subgraph[cur] > (ma2Subgraph[cur]+maZoneInput.GetFloat())) && (sc.BaseDataIn[SC_LOW][cur] <= (ma2Subgraph[cur]+sigZoneInput.GetFloat()))) { if(tradeModeInput.BooleanValue) { tSetupSubgraph[cur] = 1; } else { ddBuySubgraph[cur] = sc.BaseDataIn[SC_LOW][cur] - ddOffsetInput.GetFloat(); } } else if((ddVolSubgraph[cur] < 0) && (sc.BaseData[SC_HIGH][cur] >= ddHigh) && (ma1Subgraph[cur] < (ma2Subgraph[cur]-maZoneInput.GetFloat())) && (sc.BaseDataIn[SC_HIGH][cur] >= (ma1Subgraph[cur]-sigZoneInput.GetFloat()))) { if(tradeModeInput.BooleanValue) { tSetupSubgraph[cur] = -1; } else { ddSellSubgraph[cur] = sc.BaseDataIn[SC_HIGH][cur] + ddOffsetInput.GetFloat(); } } } else { if((ddVolSubgraph[cur] > 0) && (sc.BaseData[SC_LOW][cur] <= ddLow)) { if(tradeModeInput.BooleanValue) { tSetupSubgraph[cur] = 1; } else { ddBuySubgraph[cur] = sc.BaseDataIn[SC_LOW][cur] - ddOffsetInput.GetFloat(); } } else if((ddVolSubgraph[cur] < 0) && (sc.BaseData[SC_HIGH][cur] >= ddHigh)) { if(tradeModeInput.BooleanValue) { tSetupSubgraph[cur] = -1; } else { ddSellSubgraph[cur] = sc.BaseDataIn[SC_HIGH][cur] + ddOffsetInput.GetFloat(); } } } } if(tradeModeInput.BooleanValue) { test[cur] = inTrade; } } |