How to convert string to PChar?

Examples step by step how to make your own automated strategy or user indicator
Message
Author
tiger2616
Posts: 10
Joined: Wed Apr 24, 2019 11:57 pm

How to convert string to PChar?

#1 Postby tiger2616 » Mon Jun 17, 2019 2:37 am

Hi, All

Can anyone help me on how to convert string to PChar?

Please find the code below, I need to use bar time as part of the object name, and join some words too.

This code works well under FT2, but reports error on FT3 and FT4.

"Access violation at address 566F4B71 in module 'MSVCR120.dll'. Read of address 00000000"

It would appreciated if some one can point me to the right direction.

Thanks
Hugo

void Draw_Outer(int i, int j)
{

string name1 = "QJ ";
string name2 = name1 + to_string(Time(i));
string name3 = "Tx_" + to_string(Time(i));
string name4 = name1 + name3;
int z;

if (!ObjectExists((char*)name2.c_str()) && !ObjectExists((char*)name4.c_str()))
{
if (QJUpOrDnTBuffer[i] == 1 )// up trend
{

z = iHighest(Symbol(), Timeframe(), MODE_HIGH, i - j, j + 1);

ObjectCreate((char*)name2.c_str(), obj_TrendLine, 0, Time(i), High(z), Time(j), High(z));
ObjectSet((char*)name2.c_str(), OBJPROP_COLOR, QJ_QJLine_Color_UP);
ObjectCreate((char*)name4.c_str(), obj_Text, 0, (Time(int((i + j) / 2))), High(z) + QJ_TextDistance * Point());
ObjectSetText((char*)name4.c_str(), to_string(i - j + int(fabs(QJDHRCounterBuffer[i]))), 10, "Arial", QJ_QJLine_Color_UP);

QJDrawnBuffer[i] = 1;

}
else if ( QJUpOrDnTBuffer[i] == -1 )// down trend
{

z = iLowest(Symbol(), Timeframe(), MODE_LOW, i - j, j + 1);

ObjectCreate((char*)name2.c_str(), obj_TrendLine, 0, Time(i), Low(z), Time(j), Low(z));
ObjectSet((char*)name2.c_str(), OBJPROP_COLOR, QJ_QJLine_Color_DN);
ObjectCreate((char*)name4.c_str(), obj_Text, 0, (Time(int((i + j) / 2))), Low(z) - QJ_TextDistance * Point());
ObjectSetText((char*)name4.c_str(), to_string(i - j + int(fabs(QJDHRCounterBuffer[i]))), 10, "Arial", QJ_QJLine_Color_DN);

QJDrawnBuffer[i] = -1;

}
ObjectSet((char*)name2.c_str(), OBJPROP_WIDTH, 2);


}

}

tiger2616
Posts: 10
Joined: Wed Apr 24, 2019 11:57 pm

Re: How to convert string to PChar?

#2 Postby tiger2616 » Fri Jun 21, 2019 6:31 pm

Thanks,All.

I figured it out!


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 20 guests