Advertisement
user_137

Gann Swing

Oct 6th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.35 KB | None | 0 0
  1. #include "sierrachart.h"
  2.  
  3. SCDLLName("* Gann Swing from Kiwi *")
  4.  
  5. /***********************************************************************/
  6. SCSFExport scsf_Swing(SCStudyGraphRef sc)
  7. {
  8.     if (sc.SetDefaults)
  9.     {
  10.         sc.GraphName="GannSwing";
  11.         sc.Subgraph[0].Name="SwingUp";
  12.         sc.Subgraph[1].Name="SwingDn";
  13.         sc.Input[2].Name="Display Numbers";
  14.         sc.Input[2].ValueType=YESNO_VALUE;
  15.         sc.Input[3].Name="Number Font Size";   
  16.         sc.Input[4].Name="Price Adjust for Time";
  17.         sc.Input[5].Name="Price Adjust for Price Swing";
  18.         sc.Input[8].Name="Paintbar?";
  19.         sc.Input[8].ValueType=YESNO_VALUE;
  20.         sc.FreeDLL=0;
  21.         return;
  22.     }
  23.     if(sc.ArraySize<5) return;
  24.     sc.GraphRegion=0;
  25.  
  26.     if(sc.Input[8].GetYesNo())  
  27.     {
  28.         sc.GraphDrawType=GDT_OHLCBAR ;
  29.         sc.Subgraph[0].SecondaryColorUsed = 1;
  30.         sc.Subgraph[1].SecondaryColorUsed = 1;
  31.         sc.Subgraph[2].SecondaryColorUsed = 1;
  32.         sc.Subgraph[3].SecondaryColorUsed = 1;
  33.     } else
  34.     {
  35.         sc.Subgraph[0].DrawStyle=DRAWSTYLE_STAIR;
  36.         sc.Subgraph[1].DrawStyle=DRAWSTYLE_STAIR;
  37.     };
  38.  
  39.     int     pos, direction=1;
  40.     float   hi=sc.BaseDataIn[3][9], hinext=hi, h1=hi, h2=hi,  lo=hi, lonext=lo, l1=lo, l2=lo,
  41.         highest=0, lowest=999999, swing, start, end, length=0;
  42.  
  43.     int fs= (int) sc.Input[3].FloatValue;
  44.     if(sc.Input[4].FloatValue==sc.Input[5].FloatValue) sc.Input[5].FloatValue=sc.Input[5].FloatValue+2;
  45.     char cperiod[16];
  46.  
  47.     sc.DataStartIndex=2;
  48.     sc.DeleteACSChartDrawing(sc.ChartNumber, 0, 562);
  49.     s_UseTool Tool;
  50.     Tool.ChartNumber = sc.ChartNumber;
  51.     Tool.DrawingType = DRAWING_TEXT;
  52.     Tool.LineWidth = 1;
  53.     Tool.Region = 0;
  54.     Tool.AddMethod = UTAM_ADD_OR_ADJUST;
  55.     Tool.FontSize = fs;
  56.     Tool.LineNumber = 562;
  57.     Tool.AddMethod = UTAM_ADD_ALWAYS;
  58.  
  59.  
  60.     for (pos=10; pos < sc.ArraySize-1; pos++)
  61.     {
  62.         Tool.BeginDateTime = sc.BaseDateTimeIn[pos-2];
  63.         if(direction==1)
  64.         {
  65.             if(sc.BaseDataIn[1][pos]>highest) highest=sc.BaseDataIn[1][pos]; if(sc.BaseDataIn[2][pos]<lowest) lowest=sc.BaseDataIn[2][pos];
  66.             end=pos; swing=highest-lowest;  length=end-start;
  67.             if(sc.Input[2].BooleanValue && (sc.BaseDataIn[3][pos] < lo || pos == sc.ArraySize-1))
  68.             {
  69.                 Tool.BeginValue = highest-(int) sc.Input[4].FloatValue; Tool.Text=itoa((int)length,cperiod,10); Tool. Color = sc.Subgraph[0].PrimaryColor;
  70.                 sc.UseTool(Tool);
  71.                 Tool.BeginValue = highest-(int) sc.Input[5].FloatValue; Tool.Text=itoa((int)swing,cperiod,10); Tool. Color = sc.Subgraph[0].PrimaryColor;
  72.                 sc.UseTool(Tool);
  73.             }
  74.             if(sc.BaseDataIn[3][pos] < lo) // broken 3 day trailing lows on close
  75.             {
  76.                 direction=-1; l1=l2; l2=lonext; //reverse short
  77.                 highest=989898; lowest=999999;  start=pos;
  78.             }
  79.         } else // direction==-1
  80.         {
  81.             if(sc.BaseDataIn[1][pos]>highest) highest=sc.BaseDataIn[1][pos]; if(sc.BaseDataIn[2][pos]<lowest) lowest=sc.BaseDataIn[2][pos];
  82.             end=pos; swing=highest-lowest;  length=end-start;
  83.             if(sc.Input[2].BooleanValue && (sc.BaseDataIn[3][pos] > hi || pos == sc.ArraySize-1))
  84.             {
  85.                 Tool.BeginValue = lowest+(int) sc.Input[4].FloatValue;  Tool.Text=itoa((int)length,cperiod,10); Tool. Color = sc.Subgraph[1].PrimaryColor;
  86.                 sc.UseTool(Tool);
  87.                 Tool.BeginValue = lowest+(int) sc.Input[5].FloatValue;  Tool.Text=itoa((int)swing,cperiod,10); Tool. Color = sc.Subgraph[1].PrimaryColor;
  88.                 sc.UseTool(Tool);
  89.             }
  90.             if(sc.BaseDataIn[3][pos] > hi) // broken 3 day trailing  on close
  91.             {
  92.                 direction=1; h1=h2; h2=hinext; //reverse
  93.                 highest=0; lowest=989898;  start=pos;
  94.             }
  95.         };
  96.  
  97.  
  98.         if(sc.BaseDataIn[1][pos] > h2) // higher bar
  99.         {
  100.             h1=h2; h2=sc.BaseDataIn[1][pos];
  101.             if(sc.BaseDataIn[2][pos-1]<lonext) lonext=sc.BaseDataIn[2][pos-1];
  102.             lo=lonext; lonext=sc.BaseDataIn[2][pos];
  103.             if(lonext<lo) lo=lonext;
  104.         } else
  105.             if(sc.BaseDataIn[1][pos] > sc.BaseDataIn[1][pos-1])
  106.             { h2=sc.BaseDataIn[1][pos]; lonext=sc.BaseDataIn[2][pos]; };
  107.  
  108.  
  109.         if(sc.BaseDataIn[2][pos] < l2) // lower bar
  110.         {
  111.             l1=l2; l2=sc.BaseDataIn[2][pos];
  112.             if(sc.BaseDataIn[1][pos-1]>hinext) hinext=sc.BaseDataIn[1][pos-1];
  113.             hi=hinext; hinext=sc.BaseDataIn[1][pos];
  114.             if(hinext>hi) hi=hinext;
  115.         } else
  116.             if(sc.BaseDataIn[2][pos] < sc.BaseDataIn[2][pos-1])
  117.             { l2=sc.BaseDataIn[2][pos]; hinext=sc.BaseDataIn[1][pos]; };
  118.  
  119.  
  120.  
  121.         if(sc.BaseDataIn[1][pos] > hi) // pushed up trailing  
  122.             hi=sc.BaseDataIn[1][pos]; // pop it  because of push
  123.         if(sc.BaseDataIn[2][pos] < lo) // pushed down trailing lows  
  124.             lo=sc.BaseDataIn[2][pos]; // pop it down because of push down
  125.  
  126.         if(sc.Input[8].BooleanValue)  
  127.         {
  128.             sc.Subgraph[0].Data[pos] = sc.BaseDataIn[0][pos];  sc.Subgraph[1].Data[pos] = sc.BaseDataIn[1][pos];
  129.             sc.Subgraph[2].Data[pos] = sc.BaseDataIn[2][pos];  sc.Subgraph[3].Data[pos] = sc.BaseDataIn[3][pos];
  130.             if(direction==1) sc.Subgraph[0].DataColor[pos] = sc.Subgraph[0].PrimaryColor; else
  131.                 sc.Subgraph[0].DataColor[pos] = sc.Subgraph[0].SecondaryColor;
  132.             sc.Subgraph[1].DataColor[pos]= sc.Subgraph[0].DataColor[pos];
  133.             sc.Subgraph[2].DataColor[pos]= sc.Subgraph[0].DataColor[pos];  
  134.             sc.Subgraph[3].DataColor[pos]= sc.Subgraph[0].DataColor[pos];
  135.  
  136.         } else
  137.         {
  138.             if(highest==989898) highest=hi;  if(lowest==989898) lowest=lo;
  139.             if(direction==1) {sc.Subgraph[0].Data[pos+1] = lo; sc.Subgraph[1].Data[pos+1] = 0;}
  140.             else             {sc.Subgraph[0].Data[pos+1] =  0; sc.Subgraph[1].Data[pos+1] = hi;}
  141.             sc.Subgraph[2].Data[pos] = h1; sc.Subgraph[3].Data[pos] = h2;
  142.             sc.Subgraph[4].Data[pos] = l1; sc.Subgraph[5].Data[pos] = l2;
  143.         }
  144.     }
  145.  
  146. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement