How to code? - page 324

 
mladen:
Not that easy to explain

You have to send an event to the offline chart that will "tell" it (from your indicator) that a new tick is generated and that it should execute the required routines. It means using low level functions. The whole thing can look something like this :

#include

#import "user32.dll"

int GetParent(int hWnd);

#import

#define CHART_CMD_UPDATE_DATA 33324

void UpdateChartWindows()

{

int filePeriod = 1; // file period

string fileSymbol = "your offline symbol name";

string chartName = "your offline symbol chart full name";

string stringForName = " ";

//

//

//

//

//

int windowHandle = WindowHandle(fileSymbol,filePeriod);

if (windowHandle != 0)

{

windowHandle = GetParent(windowHandle);

windowHandle = GetWindow(windowHandle,GW_HWNDFIRST);

while (windowHandle != 0)

{

int len = GetWindowTextA(windowHandle,stringForName,80);

if (len > 0 && StringSubstr(stringForName,0,len) == chartName)

PostMessageA(windowHandle,WM_COMMAND,CHART_CMD_UPDATE_DATA,0);

windowHandle = GetWindow(windowHandle,GW_HWNDNEXT);

}

}

}

Thank you i will check it. However i find the issue for sendorder correctly. My indicator create a name for the offline chart non standard and the platforms don't open it for this reason.

Thank you for your disponibility

 

Ok, The issue for the offline chart is in work.

I have another problem.

I have to create an indicator that calculate the volumes with specific rules.

What i need is that every time there is a variation of tick the indicator must count the lenght of the swing.

Example.

on Open candel the value buffer is 0. So it must count all the tick done before a retracement but the ultimate value returned is the highest of it since the candle close.

After, it must set the color of the histogram reletated the movemenet done of the highest range returned from the buffer.

I try in different way but no succes.

Heeeeelp ^^.

Thank you

 

Thank you for all your support. I'm learn more and with all your help i fix all my request...BUT.

I have another one^^.

I need to crate a void function to recall and it have to be the merge of this two code.

The first find the last openorder. and the second find the number of the openorder that have the openprice higher.

I need to do one function for have directly the number of the order that have the highest openorderprice.

Thank you

for(int i = OrdersTotal()-1; i>= 0; i--) {

OrderSelect(i, SELECT_BY_POS);

if(OrderSymbol() == Symbol() && OrderType() == TYPE ) {

if(TYPE == OP_BUY) {

double OPrice = OrderOpenPrice();[/PHP]

[PHP]for(int e=0;e<OrdersTotal();e++) {

if(OrderSelect(e,SELECT_BY_POS,MODE_TRADES)==false ) break;

if(OrderSymbol() == Symbol() && OrderType() == TYPE) {

if(TYPE == OP_BUY) {

if(OrderOpenPrice()>test(OP_BUY) Hbuys++;

}

}

}

return(Hbuys);

}

 
dasio:
Thank you for all your support. I'm learn more and with all your help i fix all my request...BUT.

I have another one^^.

I need to crate a void function to recall and it have to be the merge of this two code.

The first find the last openorder. and the second find the number of the openorder that have the openprice higher.

I need to do one function for have directly the number of the order that have the highest openorderprice.

Thank you

for(int i = OrdersTotal()-1; i>= 0; i--) {

OrderSelect(i, SELECT_BY_POS);

if(OrderSymbol() == Symbol() && OrderType() == TYPE ) {

if(TYPE == OP_BUY) {

double OPrice = OrderOpenPrice();[/PHP]

for(int e=0;e<OrdersTotal();e++) {

if(OrderSelect(e,SELECT_BY_POS,MODE_TRADES)==false ) break;

if(OrderSymbol() == Symbol() && OrderType() == TYPE) {

if(TYPE == OP_BUY) {

if(OrderOpenPrice()>test(OP_BUY) Hbuys++;

}

}

}

return(Hbuys);

}

I did an error on second code. It's right

[PHP]for(int e=0;e<OrdersTotal();e++) {

if(OrderSelect(e,SELECT_BY_POS,MODE_TRADES)==false ) break;

if(OrderSymbol() == Symbol() && OrderType() == TYPE) {

if(TYPE == OP_BUY) {

if(OrderOpenPrice()>OPrice Hbuys++;

}

}

}

return(Hbuys);

}

 

dasio

void function is a function that does not return any value. If that is the case then the only reasonable way to do that is to use some variable that will be passed by reference to the function (in my experience using global scope variables for that purpose is a very bad practice - it avoids structured coding rules, and, in cases when error has to be looked for, it is a nightmare when such variables are used). Is that what you had in mind?

dasio:
I did an error on second code. It's right
for(int e=0;e<OrdersTotal();e++) {

if(OrderSelect(e,SELECT_BY_POS,MODE_TRADES)==false ) break;

if(OrderSymbol() == Symbol() && OrderType() == TYPE) {

if(TYPE == OP_BUY) {

if(OrderOpenPrice()>OPrice Hbuys++;

}

}

}

return(Hbuys);

}

 
mladen:
dasio void function is a function that does not return any value. If that is the case then the only reasonable way to do that is to use some variable that will be passed by reference to the function (in my experience using global scope variables for that purpose is a very bad practice - it avoids structured coding rules, and, in cases when error has to be looked for, it is a nightmare when such variables are used). Is that what you had in mind?

Thank you for your reply,

I need only the number of buy that have highest openorder and lowest openorderm respect the last buy order opened.

i must use the result how moltiplier into a vois function for some check.

So is much simpler recall this record when request. Maybe in this way so i can recall it simply CalculateCurrentBuy(Symbol())

int CalculateHighestbuy(string symbol) {

int Hopen=0;

for(int i=0;i<OrdersTotal();i++) {

code here

}

}

return(Hopen);

}

 

trailing grid?

for(int i = 1; i < Stop.Order.Levels+1; i++)

{

if(Set.SELLSTOP && s.ticketP==0){

OrderSend(Symbol(),OP_SELLSTOP,Sell.Lots+i*Sell.Multiplier,Ask-i*(Trail.SELLSTOP.Orders.Distance)*myPoint,0,0,0,0,0,0,CLR_NONE);}

if(Set.BUYSTOP && b.ticketP==0){

OrderSend(Symbol(),OP_BUYSTOP,Buy.Lots+i*Buy.Multiplier,Bid+i*(Trail.BUYSTOP.Orders.Distance)*myPoint,0,0,0,0,0,0,CLR_NONE);}

}[/CODE]

I can set a grid using the above code but how do I get the Buy Grid and Sell grid grid to trail independently or as a set and retain the separate grid spacing? I have tried all sorts of things and must be missing something obvious. All I get is either all the pending orders move to the same level and then trail as a group or the pending orders start moving up and down with the price action.

[CODE] void TrailingOrders() {

if (Trail.BUYSTOP.Orders && OrderType()==OP_BUYSTOP) {

if (OrderOpenPrice()-Ask>(Trail.BUYSTOP.Orders.Distance)*myPoint) {

OrderModify(OrderTicket(),Ask+OrderOpenPrice()+(Trail.BUYSTOP.Orders.Distance)*myPoint,OrderStopLoss(),OrderTakeProfit(), 0, Aqua);

}

}

if (Trail.SELLSTOP.Orders && OrderType()==OP_SELLSTOP) {

if (Bid-OrderOpenPrice()>(Trail.SELLSTOP.Orders.Distance)*myPoint) {

OrderModify(OrderTicket(),Bid-OrderOpenPrice()-(Trail.SELLSTOP.Orders.Distance)*myPoint,OrderStopLoss(),OrderTakeProfit(), 0, Yellow);

}

}

}

This code will trail 2 orders but how can I modify it to trail more? As soon as I try to set the trailing code up for multiple levels like the grid code above it turns to custard.

Any insight would be appreciated.

Regards CJA

 

...

cja

I tried it with the following code and it works OK (see the example picture : different steps already applied)

Did not know what are s.ticketP and b.ticketP variables ment for so used it the way you can see in the code

extern double Trail.SELLSTOP.Orders.Distance = 15;

extern double Trail.BUYSTOP.Orders.Distance = 20;

extern int Stop.Order.Levels = 4;

extern double Sell.Lots = 0.1;

extern double Sell.Multiplier = 0.1;

extern double Buy.Lots = 0.1;

extern double Buy.Multiplier = 0.2;

extern bool Set.SELLSTOP = true;

extern bool Set.BUYSTOP = true;

int init()

{

return(0);

}

int start()

{

double myPoint=1; if (Digits==3 || Digits==5) myPoint=10; myPoint *= Point;

static int s.ticketP=0;

static int b.ticketP=0;

for(int i = 1; i < Stop.Order.Levels+1; i++)

{

if(Set.SELLSTOP && s.ticketP==0){ OrderSend(Symbol(),OP_SELLSTOP,Sell.Lots+i*Sell.Multiplier,Bid-i*(Trail.SELLSTOP.Orders.Distance)*myPoint,0,0,0,0,0,0,CLR_NONE);}

if(Set.BUYSTOP && b.ticketP==0){ OrderSend(Symbol(),OP_BUYSTOP ,Buy.Lots+i *Buy.Multiplier ,Ask+i*(Trail.BUYSTOP.Orders.Distance)*myPoint ,0,0,0,0,0,0,CLR_NONE);}

}

s.ticketP=Stop.Order.Levels;

b.ticketP=Stop.Order.Levels;

return(0);

}

cja:
for(int i = 1; i < Stop.Order.Levels+1; i++)

{

if(Set.SELLSTOP && s.ticketP==0){

OrderSend(Symbol(),OP_SELLSTOP,Sell.Lots+i*Sell.Multiplier,Ask-i*(Trail.SELLSTOP.Orders.Distance)*myPoint,0,0,0,0,0,0,CLR_NONE);}

if(Set.BUYSTOP && b.ticketP==0){

OrderSend(Symbol(),OP_BUYSTOP,Buy.Lots+i*Buy.Multiplier,Bid+i*(Trail.BUYSTOP.Orders.Distance)*myPoint,0,0,0,0,0,0,CLR_NONE);}

}[/CODE]

I can set a grid using the above code but how do I get the Buy Grid and Sell grid grid to trail independently or as a set and retain the separate grid spacing? I have tried all sorts of things and must be missing something obvious. All I get is either all the pending orders move to the same level and then trail as a group or the pending orders start moving up and down with the price action.

[CODE] void TrailingOrders() {

if (Trail.BUYSTOP.Orders && OrderType()==OP_BUYSTOP) {

if (OrderOpenPrice()-Ask>(Trail.BUYSTOP.Orders.Distance)*myPoint) {

OrderModify(OrderTicket(),Ask+OrderOpenPrice()+(Trail.BUYSTOP.Orders.Distance)*myPoint,OrderStopLoss(),OrderTakeProfit(), 0, Aqua);

}

}

if (Trail.SELLSTOP.Orders && OrderType()==OP_SELLSTOP) {

if (Bid-OrderOpenPrice()>(Trail.SELLSTOP.Orders.Distance)*myPoint) {

OrderModify(OrderTicket(),Bid-OrderOpenPrice()-(Trail.SELLSTOP.Orders.Distance)*myPoint,OrderStopLoss(),OrderTakeProfit(), 0, Yellow);

}

}

}

This code will trail 2 orders but how can I modify it to trail more? As soon as I try to set the trailing code up for multiple levels like the grid code above it turns to custard.

Any insight would be appreciated.

Regards CJA
Files:
stopd.gif  36 kb
 

Trailing Grid

mladen:
cja

I tried it with the following code and it works OK (see the example picture : different steps already applied)

Did not know what are s.ticketP and b.ticketP variables ment for so used it the way you can see in the code

extern double Trail.SELLSTOP.Orders.Distance = 15;

extern double Trail.BUYSTOP.Orders.Distance = 20;

extern int Stop.Order.Levels = 4;

extern double Sell.Lots = 0.1;

extern double Sell.Multiplier = 0.1;

extern double Buy.Lots = 0.1;

extern double Buy.Multiplier = 0.2;

extern bool Set.SELLSTOP = true;

extern bool Set.BUYSTOP = true;

int init()

{

return(0);

}

int start()

{

double myPoint=1; if (Digits==3 || Digits==5) myPoint=10; myPoint *= Point;

static int s.ticketP=0;

static int b.ticketP=0;

for(int i = 1; i < Stop.Order.Levels+1; i++)

{

if(Set.SELLSTOP && s.ticketP==0){ OrderSend(Symbol(),OP_SELLSTOP,Sell.Lots+i*Sell.Multiplier,Bid-i*(Trail.SELLSTOP.Orders.Distance)*myPoint,0,0,0,0,0,0,CLR_NONE);}

if(Set.BUYSTOP && b.ticketP==0){ OrderSend(Symbol(),OP_BUYSTOP ,Buy.Lots+i *Buy.Multiplier ,Ask+i*(Trail.BUYSTOP.Orders.Distance)*myPoint ,0,0,0,0,0,0,CLR_NONE);}

}

s.ticketP=Stop.Order.Levels;

b.ticketP=Stop.Order.Levels;

return(0);

}

Hi mladen,

Thanks for your help however I may not have made myself very clear in my above post. I do not have a problem setting a grid the issue I have is trailing the grid without loosing the order separation.

s.ticketP & b.ticketP simply refers to the BUYSTOP & SELLSTOP pending orders code used elsewhere in the EA.

Regards CJA

 

Trailing Grid

cja:
Hi mladen,

Thanks for your help however I may not have made myself very clear in my above post. I do not have a problem setting a grid the issue I have is trailing the grid without loosing the order separation.

s.ticketP & b.ticketP simply refers to the BUYSTOP & SELLSTOP pending orders code used elsewhere in the EA.

Regards CJA

Hi mladen,

Any time to have a look at this?

Friendly Regards CJA

Reason: