Support Board
Date/Time: Fri, 22 Nov 2024 23:58:48 +0000
Post From: Clock code?
[2013-04-20 23:15:00] |
Kiwi - Posts: 375 |
Among other things this has a countdown timer (it also gives the high or low of the bar the active tool is over). SCSFExport scsf_Direction515b(SCStudyInterfaceRef sc) {
SCSubgraphRef oO = sc.Subgraph[0], oH = sc.Subgraph[1], oL = sc.Subgraph[2], oC = sc.Subgraph[3], Dirn = sc.Subgraph[5], Up = sc.Subgraph[6], Dn = sc.Subgraph[7] , s6 = sc.Subgraph[16], s7 = sc.Subgraph[17], s8 = sc.Subgraph[18], Bk = sc.Subgraph[9], s10 = sc.Subgraph[10], s11 = sc.Subgraph[11], s12= sc.Subgraph[12], s13 = sc.Subgraph[13], o1 = sc.Subgraph[21], o2 = sc.Subgraph[22]; SCFloatArray& O = sc.BaseDataIn[0], H = sc.BaseDataIn[1], L = sc.BaseDataIn[2], C = sc.BaseDataIn[3]; SCInputRef fontsize = sc.Input[2], shiftleft = sc.Input[3], ShowIBs = sc.Input[4], newdir = sc.Input[5]; SCDateTimeArrayRef barTime = sc.BaseDateTimeIn; if (sc.SetDefaults) { sc.GraphName="Direction 515 with chart extension"; sc.StudyDescription = "Direction for 5m and 15m HSI"; oO.Name="O Up/Dn Bar Colour"; oH.Name="H Day Inside Bar Colour"; oL.Name="L"; oC.Name="CS"; s6.Name="Direction"; Up.Name = "Up"; Dn.Name = "Dn"; s7.Name="lowesthigh"; s8.Name="highestlow"; s10.Name = "HH"; s11.Name = "LL"; s12.Name = "SwLH"; s13.Name = "SwHL"; oO.SecondaryColorUsed=1; newdir.Name="To start new direction"; newdir.SetFloat(9.5); ShowIBs.Name="Show IBs"; ShowIBs.ValueType=YESNO_VALUE; fontsize.Name="Font Size"; fontsize.SetInt(11); shiftleft.Name="Text to left"; shiftleft.SetInt(30); sc.DrawZeros=0; sc.UpdateAlways=1; sc.DataStartIndex=10; sc.CalculationPrecedence = VERY_LOW_PREC_LEVEL; sc.GraphRegion=0; sc.ScaleRangeType=SCALE_SAMEASREGION; sc.GraphDrawType=GDT_CANDLESTICK; sc.ReceiveMousePointerEvents = 1; return; } // sc.FreeDLL = 1; int as=sc.ArraySize-1; int i,updown=1,os; float up, dn, highestlow=0.0, lowestlow=0.0, swhighestlow=0.0, lowesthigh=999999.9, highesthigh=999999.9, swlowesthigh=999999.9; float& offset = sc.PersistVars->f1; int& chartselected = sc.PersistVars->i1; static int const upcolour = oO.PrimaryColor; static int const dncolour = oO.SecondaryColor; static int const oscolour = oH.PrimaryColor; if(sc.UpdateStartIndex==0) { sc.UpdateStartIndex=1; offset = newdir.FloatValue*sc.TickSize; o1.Name=" o1"; sc.SetACSToolEnable(SC_ACS_TOOL9, true); } for (i=sc.UpdateStartIndex-1; i < sc.ArraySize; i++) { int p = i - 1; updown=(int)Dirn[p]; os=(int)s6[p]; if(updown==0) updown=1; lowesthigh=s7[p]; highestlow=s8[p]; highesthigh=s10[p]; lowestlow=s11[p]; swlowesthigh=s12[p]; swhighestlow=s13[p]; float& h = H[i]; float& l = L[i]; if(updown == 1) { if(l > highestlow) swhighestlow = lowestlow = highestlow = l; } else { if(h < lowesthigh) swlowesthigh = highesthigh = lowesthigh = h; } if(h>highesthigh) highesthigh=h; if(l<lowestlow) lowestlow=l; up = highesthigh - swlowesthigh; dn = swhighestlow - lowestlow; Up[i] = up; Dn[i] = dn; os=0; if(h > lowesthigh+offset && l >= L[p] - offset) { updown = 1; highesthigh = lowesthigh = h; swhighestlow = lowestlow = highestlow = l; } else if(l < highestlow-offset && h <= H[p]+offset) { updown = -1; lowestlow = highestlow = l; swlowesthigh = highesthigh = lowesthigh = h; } // if(H[i]>H[p]+offset && L[i]<L[p]-offset) {os=1;}; if(((H[i] < H[p] && L[i] >= L[p]) || (H[i] <= H[p] && L[i] > L[p])) && ShowIBs.BooleanValue) {os = 1;}; o1[i] = 55; if(os == 1) { oO.DataColor[i] = oH.DataColor[i] = oscolour; o1[i] = 1; oL.DataColor[i] = oC.DataColor[i] = oscolour; } else if(updown >= 0) { oO.DataColor[i] = oH.DataColor[i] = upcolour; o1[i] = 33; oL.DataColor[i] = oC.DataColor[i] = upcolour; } else if(updown == -1) { oO.DataColor[i] = oH.DataColor[i] = dncolour; o1[i] = 66; oL.DataColor[i] = oC.DataColor[i] = dncolour; }; oO[i] = O[i]; oC[i] = C[i]; oH[i] = H[i]; oL[i] = L[i]; Dirn[i] = updown; s6[i] = (float)(updown); s7[i] = lowesthigh; s8[i] = highestlow; s10[i] = highesthigh; s11[i] = lowestlow; s12[i] = swlowesthigh; s13[i] = swhighestlow; } int Hour, Minute, Second; int& timesave = sc.PersistVars->i11; SCDateTime BarTime = sc.SecondsPerBar; SCString StrRemainingTime; SCDateTime RemainingTime = barTime[as].GetTime() + sc.SecondsPerBar-sc.CurrentSystemDateTime.GetTime(); if(sc.IsReplayRunning()) RemainingTime = barTime[as].GetTime() + sc.SecondsPerBar - sc.LatestDateTimeForLastBar.GetTime(); if(RemainingTime!=timesave) { float uptool = 0, dntool = 0; timesave=RemainingTime; if (sc.MenuEventID == SC_ACS_TOOL9) chartselected = sc.CurrentSystemDateTime.GetTime(); if( (sc.CurrentSystemDateTime.GetTime() - chartselected) <= 10 && sc.CurrentlySelectedDrawingTool == 2 && sc.CurrentlySelectedDrawingToolState){ uptool = Up[sc.ActiveToolIndex]; dntool = Dn[sc.ActiveToolIndex]; uptool = (uptool > 99) ? 99.0 : uptool; dntool = (dntool > 99) ? 99.0 : dntool; } up = (up > 99) ? 99.0 : Up[as]; dn = (dn > 99) ? 99.0 : Dn[as]; s_UseTool Tool; Tool.Clear(); // reset tool structure for our next use float High, Low; sc.GetMainGraphVisibleHighAndLow(High,Low); if(C[sc.IndexOfLastVisibleBar]<((High+Low)/2)) Tool.BeginValue = High-((High-Low)/60); else Tool.BeginValue = Low+(3*(High-Low)/60); Tool.BeginDateTime = barTime[sc.IndexOfLastVisibleBar - shiftleft.IntValue]; Tool.ChartNumber = sc.ChartNumber; Tool.Tool = TOOL_TEXT; Tool.LineWidth = 1; Tool.FontSize = fontsize.GetInt(); Tool.Region = 0; Tool.AddMethod = UTAM_ADD_OR_ADJUST; Tool.Color = RGB(28,28,28); char output[40]=""; if(RemainingTime<=0 && RemainingTime>=-BarTime) { RemainingTime=RemainingTime+sc.SecondsPerBar; Tool.Color = RGB(255,0,0); } else if(RemainingTime>BarTime || RemainingTime<-BarTime) RemainingTime=0; Hour=(int) (RemainingTime/3600); Minute=((int) (RemainingTime/60))-(Hour*60); Second= RemainingTime-(Hour*3600)-(Minute*60); if(Second>=10) { // if(uptool || dntool) { // StrRemainingTime.Format(" %d:%d %2.0f %2.0f : %2.0f %2.0f", Minute, // Second, up, dn, uptool, dntool); // } else { if (uptool > 0) { StrRemainingTime.Format(" %d:%d %2.0f %2.0f", Minute, Second, uptool, dntool); } else { StrRemainingTime.Format(" %d:%d %2.0f %2.0f", Minute, Second, up, dn); } } else { // if(uptool || dntool) { // StrRemainingTime.Format(" %d:0%d %2.0f %2.0f : %2.0f %2.0f", Minute, // Second, up, dn, uptool, dntool); // } else { // StrRemainingTime.Format(" %d:0%d %2.0f %2.0f", Minute, // Second, up, dn); // } if (uptool > 0) { StrRemainingTime.Format(" %d:0%d %2.0f %2.0f", Minute, Second, uptool, dntool); } else { StrRemainingTime.Format(" %d:0%d %2.0f %2.0f", Minute, Second, up, dn); } if(Minute==0) { if((Second==8||Second==6||Second==4||Second==2||Second==0)) Tool.Color = RGB(0,0,255); else Tool.Color = RGB(255,0,255); } } Tool.Text = StrRemainingTime; Tool.LineNumber = 164; sc.UseTool(Tool); } } |