Crash while setting buffer value

How to create strategies and indicators
Message
Author
schibberit
Posts: 10
Joined: Sun Feb 13, 2011 5:16 pm
Location: Please Select a Country

Crash while setting buffer value

#1 Postby schibberit » Sun Feb 13, 2011 5:25 pm

The following indicator always crashes wenn applying on a chart.
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;
...
Attachments
crash.PNG
crash.PNG (115.63 KiB) Viewed 11410 times

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Mon Feb 14, 2011 7:39 am

Hello,

Sorry cannot say where the problems is. Pelase try to remove the code "line by line" so you will see which line causes the error. Let us know if you find the error.
Check our other product here:
http://www.forexcopier.com

schibberit
Posts: 10
Joined: Sun Feb 13, 2011 5:16 pm
Location: Please Select a Country

#3 Postby schibberit » Mon Feb 14, 2011 2:25 pm

The line which causes the error is:

weeklyLow.SetValue(index,GetWeeklyLow(index));

although GetWeeklyLow returns a valid value, so this shouldnt be the problem.

The output of my print statements is:

index 75416
buffer count 75417

So the buffer size seems to be sufficient..

schibberit
Posts: 10
Joined: Sun Feb 13, 2011 5:16 pm
Location: Please Select a Country

#4 Postby schibberit » Mon Feb 14, 2011 3:09 pm

Got one step closer, crashes in this line:

void TIndexBuffer::SetValue(int index, const double value)
{
index = Count() - 1 - index;
if (index < 0) index = 0;

------> IntrfProcsRec._SetBufferValue(IntrfProcsRec.p_SetBufferValue, fBufferIndex, index, value);
}
Attachments
crash.PNG
crash.PNG (197.48 KiB) Viewed 11381 times

schibberit
Posts: 10
Joined: Sun Feb 13, 2011 5:16 pm
Location: Please Select a Country

#5 Postby schibberit » Tue Feb 15, 2011 3:24 pm

Got it running after switching to VC 2010.
Thanks.


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 6 guests