NexusFi: Find Your Edge


Home Menu

 





Help for creating slow stochastic in reference to High instead of Low


Discussion in Sierra Chart

Updated
    1. trending_up 1,028 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Help for creating slow stochastic in reference to High instead of Low

  #1 (permalink)
 sw88 
New Haven, CT/USA
 
Experience: Beginner
Platform: MT4, thinkorswim
Trading: stocks
Posts: 34 since Jul 2015
Thanks Given: 5
Thanks Received: 3

The stochastic indicator is in reference to the last N period low. I want to create another one to reference to the last N period high. I tried to modify the existing stochastic code. Cannot get it work. Can anyone help me to get it right? Many thanks!

// Windows header file
#include <windows.h>

#include "sierrachart.h"
#include "scstudyfunctions.h"

SCDLLName("Stochastic Slow to High")

void (SCDLLCALL* InternalStochasticHigh2)(SCFloatArrayRef InputDataHigh,

SCFloatArrayRef InputDataLow, SCFloatArrayRef InputDataLast, SCFloatArrayRef

FastKOut, SCFloatArrayRef FastDOut, SCFloatArrayRef SlowDOut, int Index, int

FastKLength, int FastDLength, int SlowDLength, unsigned int MovingAverageType);

void (SCDLLCALL* InternalStochasticHigh)(SCBaseDataRef BaseDataIn, SCFloatArrayRef

FastKOut, SCFloatArrayRef FastDOut, SCFloatArrayRef SlowDOut, int Index, int

FastKLength, int FastDLength, int SlowDLength, unsigned int MovingAverageType);


float GetHighest(SCFloatArrayRef In, int StartIndex, int Length);
float GetLowest(SCFloatArrayRef In, int StartIndex, int Length);

void StochasticHigh(SCBaseDataRef BaseDataIn, SCFloatArrayRef FastKOut,

SCFloatArrayRef FastDOut, SCFloatArrayRef SlowDOut, int Index, int FastKLength, int

FastDLength, int SlowDLength, unsigned int MovingAverageType);

void StochasticHigh2(SCFloatArrayRef InputDataHigh, SCFloatArrayRef InputDataLow,

SCFloatArrayRef InputDataLast, SCFloatArrayRef FastKOut, SCFloatArrayRef FastDOut,

SCFloatArrayRef SlowDOut, int Index, int FastKLength, int FastDLength, int

SlowDLength, unsigned int MovingAverageType);


/*==========================================================================*/
void StochasticHigh(SCBaseDataRef BaseDataIn, SCFloatArrayRef FastKOut,

SCFloatArrayRef FastDOut, SCFloatArrayRef SlowDOut, int Index, int FastKLength, int

FastDLength, int SlowDLength, unsigned int MovingAverageType)
{
StochasticHigh2(BaseDataIn[SC_HIGH], BaseDataIn[SC_LOW], BaseDataIn[SC_LAST],

FastKOut, FastDOut, SlowDOut, Index, FastKLength, FastDLength, SlowDLength,

MovingAverageType);
}

/*==========================================================================*/
void StochasticHigh2(SCFloatArrayRef InputDataHigh, SCFloatArrayRef InputDataLow,

SCFloatArrayRef InputDataLast, SCFloatArrayRef FastKOut, SCFloatArrayRef FastDOut,

SCFloatArrayRef SlowDOut, int Index, int FastKLength, int FastDLength, int

SlowDLength, unsigned int MovingAverageType)
{
float High = GetHighest(InputDataHigh, Index, FastKLength);
float Low = GetLowest(InputDataLow, Index, FastKLength);

float Range = High - Low;
if (Range == 0)
FastKOut[Index] = 100.0f;
else
FastKOut[Index] = 100.0f * (High - InputDataLast[Index]) / Range;

MovingAverage_S(FastKOut, FastDOut, MovingAverageType, Index, FastDLength);
MovingAverage_S(FastDOut, SlowDOut, MovingAverageType, Index, SlowDLength);
}

/****************/
SCSFExport scsf_SlowStochasticHigh(SCStudyInterfaceRef sc)
{
SCSubgraphRef SlowK = sc.Subgraph[0];
SCSubgraphRef SlowD = sc.Subgraph[1];
SCSubgraphRef Line1 = sc.Subgraph[2];
SCSubgraphRef Line2 = sc.Subgraph[3];
SCSubgraphRef Temp4 = sc.Subgraph[4];

SCInputRef FastKLength = sc.Input[2];
SCInputRef FastDLength = sc.Input[3];
SCInputRef SlowDLength = sc.Input[4];
SCInputRef Line1Value = sc.Input[5];
SCInputRef Line2Value = sc.Input[6];
SCInputRef MovAvgType = sc.Input[7];
SCInputRef InputDataHigh = sc.Input[8];
SCInputRef InputDataLow = sc.Input[9];
SCInputRef InputDataLast = sc.Input[10];
SCInputRef UpdateFlag = sc.Input[11];

if ( sc.SetDefaults )
{
sc.GraphName = "StochasticHigh - Slow";

sc.ValueFormat = 2;

SlowK.Name = "Slow %K";
SlowK.DrawStyle = DRAWSTYLE_LINE;
SlowK.PrimaryColor = RGB(0,255,0);
SlowK.DrawZeros = true;

SlowD.Name = "Slow %D";
SlowD.DrawStyle = DRAWSTYLE_LINE;
SlowD.PrimaryColor = RGB(255,0,255);
SlowD.DrawZeros = true;

Line1.Name = "Line1";
Line1.DrawStyle = DRAWSTYLE_LINE;
Line1.PrimaryColor = RGB(255,255,0);
Line1.DrawZeros = true;

Line2.Name = "Line2";
Line2.DrawStyle = DRAWSTYLE_LINE;
Line2.PrimaryColor = RGB(255,127,0);
Line2.DrawZeros = true;

FastKLength.Name = "Fast %K Length";
FastKLength.SetInt(10);
FastKLength.SetIntLimits(1,MAX_STUDY_LENGTH);

FastDLength.Name = "Fast %D Length (Slow %K)";
FastDLength.SetInt(3);
FastDLength.SetIntLimits(1,MAX_STUDY_LENGTH);

SlowDLength.Name = "Slow %D Length";
SlowDLength.SetInt(3);
SlowDLength.SetIntLimits(1,MAX_STUDY_LENGTH);

Line1Value.Name = "Line1 Value";
Line1Value.SetFloat(70);

Line2Value.Name = "Line2 Value";
Line2Value.SetFloat(30);

MovAvgType.Name = "Moving Average Type";
MovAvgType.SetMovAvgType(MOVAVGTYPE_SIMPLE);

InputDataHigh.Name = "Input Data for High";
InputDataHigh.SetInputDataIndex(SC_HIGH);

InputDataLow.Name = "Input Data for Low";
InputDataLow.SetInputDataIndex(SC_LOW);

InputDataLast.Name = "Input Data for Last";
InputDataLast.SetInputDataIndex(SC_LAST);

UpdateFlag.SetInt(1); //update flag

sc.AutoLoop = true;
return;
}


sc.DataStartIndex = FastKLength.GetInt() + FastDLength.GetInt() +

SlowDLength.GetInt();

sc.StochasticHigh(
sc.BaseData[InputDataHigh.GetInputDataIndex()],
sc.BaseData[InputDataLow.GetInputDataIndex()],
sc.BaseData[InputDataLast.GetInputDataIndex()],
Temp4, // Data member is Fast %K
FastKLength.GetInt(),
FastDLength.GetInt(),
SlowDLength.GetInt(),
MovAvgType.GetMovAvgType()
);

SlowK[sc.Index] = Temp4.Arrays[0][sc.Index];
SlowD[sc.Index] = Temp4.Arrays[1][sc.Index];

Line1[sc.Index] = Line1Value.GetFloat();
Line2[sc.Index] = Line2Value.GetFloat();

return;


}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Strategy stop orders partially filled
EasyLanguage Programming
Discipline isnt about fortitude. Its about conviction!
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
72 thanks
Spoo-nalysis ES e-mini futures S&P 500
18 thanks
Self sabotage reframed
15 thanks
Trading with Intuition
15 thanks
GFIs1 1 DAX trade per day journal
14 thanks
  #3 (permalink)
 sw88 
New Haven, CT/USA
 
Experience: Beginner
Platform: MT4, thinkorswim
Trading: stocks
Posts: 34 since Jul 2015
Thanks Given: 5
Thanks Received: 3


Please ignore the above request. I found a much simpler roundabout. It's just 100-stochastic

Started this thread Reply With Quote




Last Updated on February 5, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts