Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 17:46:19 +0000



How to compare EMA to price?

View Count: 1532

[2014-05-21 19:38:46]
User12676 - Posts: 70
I have done

sc.ExponentialMovAvg(sc.BaseDataIn[SC_LAST], sc.Subgraph[0], 20);
float ExponentialMovAvg = sc.Subgraph[0][sc.Index];

if (price < ExponentialMovAvg) { do something } <--- but this doesnt work

How do you compare price to an ema properly?
[2014-05-21 19:46:17]
Sierra Chart Engineering - Posts: 104368
if (price < sc.Subgraph[0][sc.Index])

Refer to:
http://www.sierrachart.com/index.php?l=doc/doc_ACS_ArraysAndLooping.html
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2014-05-21 20:36:53]
User12676 - Posts: 70
I think the problem is that after initialization of the EMA array, I cannot even see it on the chart. Yes i have it defined

SCSubgraphRef ExponentialMA = sc.Subgraph[1];
ExponentialMA.Name = "Exponential Moving Average";
ExponentialMA.DrawStyle = DRAWSTYLE_LINE;
ExponentialMA.PrimaryColor = RGB(255,0,255);
sc.SimpleMovAvg(sc.BaseDataIn[SC_LAST], ExponentialMA, 20);

How come I don't see it on the chart?
[2014-05-21 20:39:19]
User12676 - Posts: 70
Its like the initialization is not working...
[2014-05-21 20:40:01]
User12676 - Posts: 70
I was switching between simple and exponential to see if there was a bug... hence the mismatch in variable names
[2014-05-21 20:41:58]
Sierra Chart Engineering - Posts: 104368
We need to see the complete study function.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2014-05-21 20:56:29]
User12676 - Posts: 70
Strange, when I put it in a study file all by itself, it works. When I add if to my study, it doesnt....
I modified the zig zag study and added it there

SCSFExport scsf_ZigZagCumulativeVolumeStudy(SCStudyInterfaceRef sc)
{
  SCSubgraphRef ZigZagLine = sc.Subgraph[0];

  SCSubgraphRef Accumulated = sc.Subgraph[4];
  sc.Subgraph[4].LineWidth = 6;
  
  SCSubgraphRef VPM = sc.Subgraph[7];
  
  SCSubgraphRef AccumulatedVolumeOpenClose = sc.Subgraph[6];
  SCSubgraphRef ER = sc.Subgraph[8];
  
  AccumulatedVolume = sc.Subgraph[9];
  AccumulatedDiffVolume = sc.Subgraph[10];
  AccumulatedLegTime = sc.Subgraph[11];

  ZA = sc.Subgraph[12];
  ZU = sc.Subgraph[13];
  ZD = sc.Subgraph[14];

  SCSubgraphRef Long = sc.Subgraph[20];
  SCSubgraphRef Short = sc.Subgraph[21];


  SCSubgraphRef ExponentialMA = sc.Subgraph[99];

  SCInputRef VolumeToAccumulate = sc.Input [0];
  
  SCInputRef VersionUpdate = sc.Input[14];
  SCInputRef CalculationMode = sc.Input[17];
  SCInputRef ReversalAmount = sc.Input[19];
  SCInputRef NumberBarsForReversal = sc.Input[20];
  SCInputRef RangeRatio = sc.Input[21];
  SCInputRef Invert = sc.Input[22];
  SCInputRef ShowBidVolumePositive = sc.Input[23];
  SCInputRef BlendedVolumePeriod = sc.Input[24];
  SCInputRef ActiveMarketHours = sc.Input[25];
  
  //HIDDEN
  SCInputRef CalcOnBarClose = sc.Input[49];
  SCInputRef InputDataHigh = sc.Input[50];
  SCInputRef InputDataLow = sc.Input[51];
  SCInputRef ReversalPercent = sc.Input[54];
  
  if(sc.SetDefaults)
  {
    //During development set this flag to 1, so the DLL can be modified.
    //When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 1;  
  
    sc.GraphName="MIKE WAVE ALERT";
  
    //Manual looping
    sc.AutoLoop = 0;
    sc.ValueFormat= 0;
    //MIKE sc.GraphRegion = 1;
    sc.GraphRegion = 0;

    ZigZagLine.Name = "MIKE WAVE ALERT";
    ZigZagLine.DrawStyle = DRAWSTYLE_IGNORE;

    Accumulated.Name= "Accumulated";
    //MIKE Accumulated.DrawStyle = DRAWSTYLE_BAR;
    Accumulated.DrawStyle = DRAWSTYLE_IGNORE;
    Accumulated.SecondaryColorUsed = 1;
    Accumulated.PrimaryColor = RGB(90,150,231);
    Accumulated.SecondaryColor = RGB(167,48,48);

    ER.Name= "Effort Reward Bars";
    ER.DrawStyle = DRAWSTYLE_COLORBAR;
    ER.SecondaryColorUsed = 1;
    ER.PrimaryColor = RGB(0,255,255);
    ER.SecondaryColor = RGB(255,0,0);    
      
    VolumeToAccumulate.Name= "Volume To Accumulate";
    VolumeToAccumulate.SetCustomInputStrings("Total Volume;Ask Bid Volume Difference;Force Ratio;Cum Momentum + Cum Momentum Diff;Cum Momentum + Per Bar Momentum Diff;Cum Momentum + Per Bar Momentum and Volume Diff;Cum Momentum;Cum Momentum + Per Bar Volume Diff;Blended Volume Diff;Blended Volume Total;Leg Time");
    VolumeToAccumulate.SetCustomInputIndex(10);

    VersionUpdate.SetInt(1);

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

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

    CalculationMode.Name = "Mode (1,2,3)";
    CalculationMode.SetInt(2);
    CalculationMode.SetIntLimits(1, 3);

    ReversalPercent.Name = "Reversal % for Mode 1";
    ReversalPercent.SetFloat(.05f);

    //ORIG ReversalAmount.Name = "Reversal Amount for Mode 2,3";
    ReversalAmount.Name = "Reversal Amount";
    ReversalAmount.SetFloat(0.5f);

    NumberBarsForReversal.Name = "Bars Required for Reversal (Mode 2)";
    NumberBarsForReversal.SetInt(1);

    CalcOnBarClose.Name = "Calculate New Values On Bar Close";
    CalcOnBarClose.SetYesNo(1);
    
    ShowBidVolumePositive.Name = "Show Bid Volume As Positive";
    ShowBidVolumePositive.SetYesNo(0);
    
    RangeRatio.Name = "Range Ratio (Per bar, not cumulative)";
    RangeRatio.SetCustomInputStrings("None;Open / Close;High / Low");
    RangeRatio.SetCustomInputIndex(0);    

    Invert.Name = "Invert";
    Invert.SetYesNo(0);

    BlendedVolumePeriod.Name = "Blended Volume Period";
    BlendedVolumePeriod.SetInt(10);
    
    ActiveMarketHours.Name = "Active Market Hours (For Leg Time)";
    ActiveMarketHours.SetString("0630-1115");

    // Volume Price Mismatch Bars
    VPM.Name = "Volume Price Mismatch";
    VPM.DrawStyle = DRAWSTYLE_BAR;
    VPM.DrawZeros = false;
    VPM.SecondaryColorUsed = 1;
    VPM.PrimaryColor = RGB(128,128,128);  
    VPM.SecondaryColor = RGB(128,128,128);  

    // Long Color
    Long.Name = "Long";
    Long.DrawStyle = DRAWSTYLE_COLORBAR;
    Long.PrimaryColor = RGB(90,150,231);
    Long.DrawZeros = false;            

    // Short Color
    Short.Name = "Short";
    Short.DrawStyle = DRAWSTYLE_COLORBAR;
    Short.PrimaryColor = RGB(204,88,146);
    Short.DrawZeros = false;  

    ExponentialMA.Name = "Exponential Moving Average";
    ExponentialMA.DrawStyle = DRAWSTYLE_LINE;
    ExponentialMA.PrimaryColor = RGB(255,0,255);

    return;
  }

  sc.ExponentialMovAvg(sc.Close, ExponentialMA, 20);
[2014-05-21 22:57:00]
User12676 - Posts: 70
Ok, well i deleted most of the code and have this left and it still doesnt draw the EMA on the chart....
Very wierd

// The top of every source code file must include this line
#include "sierrachart.h"


// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("MIKE_WAVE_ALERT")



/*==========================================================================*/
SCSFExport scsf_ZigZagCumulativeVolumeStudy(SCStudyInterfaceRef sc)
{

  SCSubgraphRef ExponentialMA = sc.Subgraph[1];
  ExponentialMA.Name = "Exponential Moving Average";
  ExponentialMA.DrawStyle = DRAWSTYLE_LINE;
  ExponentialMA.PrimaryColor = RGB(255,0,255);


  
  if(sc.SetDefaults)
  {
    //During development set this flag to 1, so the DLL can be modified.
    //When development is completed, set it to 0 to improve performance.
    sc.FreeDLL = 1;  
  
    sc.GraphName="MIKE WAVE ALERT";
  
    //Manual looping
    sc.AutoLoop = 0;
    sc.GraphRegion = 0;


    return;
  }


sc.ExponentialMovAvg(sc.BaseDataIn[SC_LAST], ExponentialMA, 20);


}

[2014-05-21 23:08:44]
User12676 - Posts: 70
Well, after figiting it has to do with the autoloop. Please advise how to properly calculate EMA when doing manual loop in the zig zag study
[2014-05-21 23:11:16]
Sierra Chart Engineering - Posts: 104368
You need to read the documentation here about this:

http://www.sierrachart.com/index.php?l=doc/doc_ACS_ArraysAndLooping.html

We will not provide more help than this.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2014-05-21 23:46:25]
User12676 - Posts: 70
Thank you. I finally got it working.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account