The crash occurs in CalculateValue while setting the first buffer value.
Code: Select all
#include <Windows.h>
#include <stdio.h>
#include <algorithm>
#include "IndicatorInterfaceUnit.h"
#include "TechnicalFunctions.h"
TIndexBuffer weeklyLow;
TIndexBuffer weeklyHigh;
void PrintChars(char* printStr)
{
char buff[30];
sprintf(buff,printStr);
Print(buff);
}
void PrintNum(char* format, int printNum)
{
char buff[30];
sprintf(buff,format,printNum);
Print(buff);
}
void PrintNum(char* format, unsigned int printNum)
{
char buff[30];
sprintf(buff,format,printNum);
Print(buff);
}
void PrintNum(char* format, double printNum)
{
char buff[30];
sprintf(buff,format,printNum);
Print(buff);
}
extern "C" __declspec(dllexport) void Init()
{
IndicatorShortName("HN HighLow");
SetOutputWindow(ow_ChartWindow);
//Set buffers
IndicatorBuffers(2);
weeklyHigh = CreateIndexBuffer();
weeklyLow = CreateIndexBuffer();
SetIndexBuffer(0, weeklyHigh);
SetIndexStyle(0,ds_Line, psSolid, 1,clRed);
SetIndexLabel(0, "Weekly High");
SetEmptyValue(0);
SetIndexBuffer(1, weeklyLow);
SetIndexStyle(1,ds_Line, psSolid, 1,clRed);
SetIndexLabel(1, "Weekly Low");
}
int GetLastWeekBarShift(int index)
{
TDateTime time = iTime(Symbol(),Timeframe(),index);
//PrintNum("time %f",time);
if(IntrfProcsRec.iBarShift==NULL)
Print("doh !");
int barShift = iBarShift(Symbol(),PERIOD_W1,time,false);
PrintNum("barShift %i",barShift);
return barShift;
}
double GetWeeklyLow(int index)
{
double low = iLow(Symbol(),PERIOD_W1,GetLastWeekBarShift(index));
PrintNum("wLow %f",low);
return low;
}
double GetWeeklyHigh(int index)
{
return iHigh(Symbol(),PERIOD_W1,GetLastWeekBarShift(index));
}
void __stdcall Done()
{}
extern "C" __declspec(dllexport) void Calculate(int index)
{
PrintNum("index %i",index);
PrintNum("buffer count %i",weeklyLow.Count());
weeklyLow.SetValue(index,GetWeeklyLow(index));
weeklyHigh.SetValue(index,GetWeeklyHigh(index));
}
Any hints ?
Also I cannot get iBarShift to work, which always returns -1 because of
Code: Select all
int iBarShift(PChar Symbol, int TimeFrame, TDateTime time, bool Exact)
{
if (IntrfProcsRec.iBarShift == NULL) return -1;
...