Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sierrachart.h"
- SCDLLName("* Gann Swing from Kiwi *")
- /***********************************************************************/
- SCSFExport scsf_Swing(SCStudyGraphRef sc)
- {
- if (sc.SetDefaults)
- {
- sc.GraphName="GannSwing";
- sc.Subgraph[0].Name="SwingUp";
- sc.Subgraph[1].Name="SwingDn";
- sc.Input[2].Name="Display Numbers";
- sc.Input[2].ValueType=YESNO_VALUE;
- sc.Input[3].Name="Number Font Size";
- sc.Input[4].Name="Price Adjust for Time";
- sc.Input[5].Name="Price Adjust for Price Swing";
- sc.Input[8].Name="Paintbar?";
- sc.Input[8].ValueType=YESNO_VALUE;
- sc.FreeDLL=0;
- return;
- }
- if(sc.ArraySize<5) return;
- sc.GraphRegion=0;
- if(sc.Input[8].GetYesNo())
- {
- sc.GraphDrawType=GDT_OHLCBAR ;
- sc.Subgraph[0].SecondaryColorUsed = 1;
- sc.Subgraph[1].SecondaryColorUsed = 1;
- sc.Subgraph[2].SecondaryColorUsed = 1;
- sc.Subgraph[3].SecondaryColorUsed = 1;
- } else
- {
- sc.Subgraph[0].DrawStyle=DRAWSTYLE_STAIR;
- sc.Subgraph[1].DrawStyle=DRAWSTYLE_STAIR;
- };
- int pos, direction=1;
- float hi=sc.BaseDataIn[3][9], hinext=hi, h1=hi, h2=hi, lo=hi, lonext=lo, l1=lo, l2=lo,
- highest=0, lowest=999999, swing, start, end, length=0;
- int fs= (int) sc.Input[3].FloatValue;
- if(sc.Input[4].FloatValue==sc.Input[5].FloatValue) sc.Input[5].FloatValue=sc.Input[5].FloatValue+2;
- char cperiod[16];
- sc.DataStartIndex=2;
- sc.DeleteACSChartDrawing(sc.ChartNumber, 0, 562);
- s_UseTool Tool;
- Tool.ChartNumber = sc.ChartNumber;
- Tool.DrawingType = DRAWING_TEXT;
- Tool.LineWidth = 1;
- Tool.Region = 0;
- Tool.AddMethod = UTAM_ADD_OR_ADJUST;
- Tool.FontSize = fs;
- Tool.LineNumber = 562;
- Tool.AddMethod = UTAM_ADD_ALWAYS;
- for (pos=10; pos < sc.ArraySize-1; pos++)
- {
- Tool.BeginDateTime = sc.BaseDateTimeIn[pos-2];
- if(direction==1)
- {
- if(sc.BaseDataIn[1][pos]>highest) highest=sc.BaseDataIn[1][pos]; if(sc.BaseDataIn[2][pos]<lowest) lowest=sc.BaseDataIn[2][pos];
- end=pos; swing=highest-lowest; length=end-start;
- if(sc.Input[2].BooleanValue && (sc.BaseDataIn[3][pos] < lo || pos == sc.ArraySize-1))
- {
- Tool.BeginValue = highest-(int) sc.Input[4].FloatValue; Tool.Text=itoa((int)length,cperiod,10); Tool. Color = sc.Subgraph[0].PrimaryColor;
- sc.UseTool(Tool);
- Tool.BeginValue = highest-(int) sc.Input[5].FloatValue; Tool.Text=itoa((int)swing,cperiod,10); Tool. Color = sc.Subgraph[0].PrimaryColor;
- sc.UseTool(Tool);
- }
- if(sc.BaseDataIn[3][pos] < lo) // broken 3 day trailing lows on close
- {
- direction=-1; l1=l2; l2=lonext; //reverse short
- highest=989898; lowest=999999; start=pos;
- }
- } else // direction==-1
- {
- if(sc.BaseDataIn[1][pos]>highest) highest=sc.BaseDataIn[1][pos]; if(sc.BaseDataIn[2][pos]<lowest) lowest=sc.BaseDataIn[2][pos];
- end=pos; swing=highest-lowest; length=end-start;
- if(sc.Input[2].BooleanValue && (sc.BaseDataIn[3][pos] > hi || pos == sc.ArraySize-1))
- {
- Tool.BeginValue = lowest+(int) sc.Input[4].FloatValue; Tool.Text=itoa((int)length,cperiod,10); Tool. Color = sc.Subgraph[1].PrimaryColor;
- sc.UseTool(Tool);
- Tool.BeginValue = lowest+(int) sc.Input[5].FloatValue; Tool.Text=itoa((int)swing,cperiod,10); Tool. Color = sc.Subgraph[1].PrimaryColor;
- sc.UseTool(Tool);
- }
- if(sc.BaseDataIn[3][pos] > hi) // broken 3 day trailing on close
- {
- direction=1; h1=h2; h2=hinext; //reverse
- highest=0; lowest=989898; start=pos;
- }
- };
- if(sc.BaseDataIn[1][pos] > h2) // higher bar
- {
- h1=h2; h2=sc.BaseDataIn[1][pos];
- if(sc.BaseDataIn[2][pos-1]<lonext) lonext=sc.BaseDataIn[2][pos-1];
- lo=lonext; lonext=sc.BaseDataIn[2][pos];
- if(lonext<lo) lo=lonext;
- } else
- if(sc.BaseDataIn[1][pos] > sc.BaseDataIn[1][pos-1])
- { h2=sc.BaseDataIn[1][pos]; lonext=sc.BaseDataIn[2][pos]; };
- if(sc.BaseDataIn[2][pos] < l2) // lower bar
- {
- l1=l2; l2=sc.BaseDataIn[2][pos];
- if(sc.BaseDataIn[1][pos-1]>hinext) hinext=sc.BaseDataIn[1][pos-1];
- hi=hinext; hinext=sc.BaseDataIn[1][pos];
- if(hinext>hi) hi=hinext;
- } else
- if(sc.BaseDataIn[2][pos] < sc.BaseDataIn[2][pos-1])
- { l2=sc.BaseDataIn[2][pos]; hinext=sc.BaseDataIn[1][pos]; };
- if(sc.BaseDataIn[1][pos] > hi) // pushed up trailing
- hi=sc.BaseDataIn[1][pos]; // pop it because of push
- if(sc.BaseDataIn[2][pos] < lo) // pushed down trailing lows
- lo=sc.BaseDataIn[2][pos]; // pop it down because of push down
- if(sc.Input[8].BooleanValue)
- {
- sc.Subgraph[0].Data[pos] = sc.BaseDataIn[0][pos]; sc.Subgraph[1].Data[pos] = sc.BaseDataIn[1][pos];
- sc.Subgraph[2].Data[pos] = sc.BaseDataIn[2][pos]; sc.Subgraph[3].Data[pos] = sc.BaseDataIn[3][pos];
- if(direction==1) sc.Subgraph[0].DataColor[pos] = sc.Subgraph[0].PrimaryColor; else
- sc.Subgraph[0].DataColor[pos] = sc.Subgraph[0].SecondaryColor;
- sc.Subgraph[1].DataColor[pos]= sc.Subgraph[0].DataColor[pos];
- sc.Subgraph[2].DataColor[pos]= sc.Subgraph[0].DataColor[pos];
- sc.Subgraph[3].DataColor[pos]= sc.Subgraph[0].DataColor[pos];
- } else
- {
- if(highest==989898) highest=hi; if(lowest==989898) lowest=lo;
- if(direction==1) {sc.Subgraph[0].Data[pos+1] = lo; sc.Subgraph[1].Data[pos+1] = 0;}
- else {sc.Subgraph[0].Data[pos+1] = 0; sc.Subgraph[1].Data[pos+1] = hi;}
- sc.Subgraph[2].Data[pos] = h1; sc.Subgraph[3].Data[pos] = h2;
- sc.Subgraph[4].Data[pos] = l1; sc.Subgraph[5].Data[pos] = l2;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement