Logic problem I think.... looking for help:)

 
int start()
{
//----
int action = 0;
double loty = 1/100;
int course = Bid ;
int lastOpenTime = 0, Ticket = 0 ;
double point = MarketInfo(Symbol(),MODE_POINT);
double diference = 50*point;
bool result;
double price, Oprice;
int cmd, error;lem 


//1------------------------------------------------

for ( int i =   OrdersTotal () - 1   ; i >= 0 ; i -- )
{
   //2-------------------------------------------------
if (OrderSelect(i, SELECT_BY_POS)

&& OrderSymbol() == Symbol()

&& OrderType() == OP_BUY || OP_SELL ){

Oprice = OrderOpenPrice ();
Ticket = OrderTicket ();
}
  //2------------------------------------------------
if (Ticket <= 0 )
{
  action=OrderSend(Symbol(),OP_BUY,0.01,Ask,5,0,0,"buying",Ticket + 1,0,Blue);
if(action<=0) Print("Error = ",GetLastError());
Sleep(1000);
action=OrderSend(Symbol(),OP_SELL,0.01,Bid,5,0,0,"selling",Ticket + 2,0,CLR_NONE);
if(action<=0) Print("Error = ",GetLastError());
}
//1------------------------------------------------

}
   return(0);
  }

Do you know what i do wrong?

Why this code isn't sending orders?

 
if (Ticket <= 0 ) -------------------> because this FALSE.

and the following line is nonsense.

&& OrderType() == OP_BUY || OP_SELL ){ --------------------> OP_SELL no boolean output. it is constant 
 
diostar:


thanks i was thinking about that op_buy || op_ sell // one problem less:)

but the ticket musn't be false, becouse if there is any order than it will be selected and the Ticket = OrderTicket () that is more than zero.

It should send orders only when there is no orders on the market. This is first stage of code....

 
BorysekPL:


thanks i was thinking about that op_buy || op_ sell // one problem less:)

but the ticket musn't be false, becouse if there is any order than it will be selected and the Ticket = OrderTicket () that is more than zero.

It should send orders only when there is no orders on the market. This is first stage of code....

correct. I see thru your logic. your code should be amended to (see below):

for ( int i =   OrdersTotal () - 1   ; i >= 0 ; i -- )
{
   //2-------------------------------------------------
if (OrderSelect(i, SELECT_BY_POS)

&& OrderSymbol() == Symbol()

&& (OrderType() == OP_BUY || (OrderType() ==OP_SELL) ){ <----amended

Oprice = OrderOpenPrice ();
Ticket = OrderTicket ();
}
 
} ////////////////<------------------------------------- amended: close the loop

 //2------------------------------------------------
if (Ticket <= 0 )
{
  action=OrderSend(Symbol(),OP_BUY,0.01,Ask,5,0,0,"buying",Ticket + 1,0,Blue);
if(action<=0) Print("Error = ",GetLastError());
Sleep(1000);
action=OrderSend(Symbol(),OP_SELL,0.01,Bid,5,0,0,"selling",Ticket + 2,0,CLR_NONE);
if(action<=0) Print("Error = ",GetLastError());
}
//1------------------------------------------------

}

also...

if(OrdersTotal()<1){ ....
or
if(OrdersTotal()>0){ ...
//<------
 

rather, even before that loop starts, this shuld be there in the first place.

 
if(OrdersTotal()<1){ ....
This makes the EA incompatible with every other including itself on other charts and manual trading
int ticket = 0;
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    ){
        ticket = OrderTicket();
    }
Use one magic number to differentiate your orders from others. Use the OrderType to determine direction, not MN.
 
WHRoeder:
This makes the EA incompatible with every other including itself on other charts and manual trading Use one magic number to differentiate your orders from others. Use the OrderType to determine direction, not MN.

int start()
{
//----
int action = 0;
double loty = 1/100;
int course = Bid ;
int lastOpenTime = 0, Ticket = 0 ;
double point = MarketInfo(Symbol(),MODE_POINT);
double diference = 50*point;
double lowdiference = 40*point;
double highdiference = 60*point;
bool result;
double price, Oprice;
int CMD, error;


//1------------------------------------------------

for ( int i =   OrdersTotal () - 1   ; i >= 0 ; i -- )
{
   //2-------------------------------------------------
if (OrderSelect(i, SELECT_BY_POS)

&& OrderSymbol() == Symbol())
{
     CMD = OrderType ();
     //3-----------------------------------------------
     if (CMD == OP_SELL || OP_BUY )
     {
     Oprice = OrderOpenPrice ();
     Ticket = OrderMagicNumber ();
     }
}
}
  //2------------------------------------------------
if (Oprice <= 0 )
{
action=OrderSend(Symbol(),OP_BUY,0.01,Ask,5,0,0,"BUYING",Ticket + 1,0,Blue);
if(action<=0) Print("Error = ",GetLastError());
Sleep(1000);
action=OrderSend(Symbol(),OP_SELL,0.01,Bid,5,0,0,"SELLING",Ticket + 2,0,Red);
if(action<=0) Print("Error = ",GetLastError());
}
  //2------------------------------------------------
if (Oprice >=1 &&  course >= Oprice + diference)
{
    //3----------------------------------------------
if (OrderSelect(i, SELECT_BY_POS)

&& OrderMagicNumber() == Ticket

&& OrderSymbol() == Symbol()

&& OrderType() == OP_BUY )
{
       //4----------------------------------------------
       if (!OrderClose(OrderTicket(),OrderLots(),price,4,CLR_NONE))
       { Print("Error closing last SELL order : ",GetLastError()); 
       }
}
    //3-----------------------------------------------

    if (OrderSelect(i, SELECT_BY_POS)
    && OrderMagicNumber () == Ticket - 1

    && OrderSymbol () == Symbol()

    && OrderType () == OP_BUY )
       {
        //4-------------------------------------------
        if (!OrderClose(OrderTicket(),OrderLots(),price,4,CLR_NONE))
        { Print("Error closing last SELL order : ",GetLastError()); 
        }
       }
    //3-----------------------------------------------
    if (!OrderSelect(i, SELECT_BY_POS)

    && OrderSymbol () == Symbol()

    && OrderType () == OP_BUY 
    
    && OrderOpenPrice () >= Oprice + lowdiference 
    
    && OrderOpenPrice () <= Oprice + highdiference )
        {
        //4-------------------------------------------
        action=OrderSend(Symbol(),OP_BUY,0.01,Ask,5,0,0,"BUYING",Ticket + 1,0,Blue);
        if(action<=0) Print("Error = ",GetLastError());
        Sleep(1000);
        action=OrderSend(Symbol(),OP_SELL,0.01,Bid,5,0,0,"SELLING",Ticket + 2,0,Red);
        if(action<=0) Print("Error = ",GetLastError());
        }
    //3-----------------------------------------------
    else
        {
        if (OrderSelect(i, SELECT_BY_POS)

        && OrderSymbol () == Symbol()

        && OrderType () == OP_BUY 
    
        && OrderOpenPrice () >= Oprice + lowdiference 
    
        && OrderOpenPrice () <= Oprice + highdiference )
        {
        //4-------------------------------------------
        action=OrderSend(Symbol(),OP_BUY,0.01,Ask,5,0,0,"BUYING",Ticket + 1,0,Blue);
        if(action<=0) Print("Error = ",GetLastError());
        }
      }  
  }
  //2-------------------------------------------------


return (0)
}

Meantime i've code it with your sugestions and some new ideas.

Now this is compiled but it doesn't work ok.

It only sends two orders at the begining:

for ( int i =   OrdersTotal () - 1   ; i >= 0 ; i -- )
{
   //2-------------------------------------------------
if (OrderSelect(i, SELECT_BY_POS)

&& OrderSymbol() == Symbol())
{
     CMD = OrderType ();
     //3-----------------------------------------------
     if (CMD == OP_SELL || OP_BUY )
     {
     Oprice = OrderOpenPrice ();
     Ticket = OrderMagicNumber ();
     }
}
}
  //2------------------------------------------------
if (Oprice <= 0 )
{
action=OrderSend(Symbol(),OP_BUY,0.01,Ask,5,0,0,"BUYING",Ticket + 1,0,Blue);
if(action<=0) Print("Error = ",GetLastError());
Sleep(1000);
action=OrderSend(Symbol(),OP_SELL,0.01,Bid,5,0,0,"SELLING",Ticket + 2,0,Red);
if(action<=0) Print("Error = ",GetLastError());
}

But than it stops and there is no other action.

I think that this is some logic problem, perhaps at this moment:

if (!OrderSelect(i, SELECT_BY_POS)

    && OrderSymbol () == Symbol()

    && OrderType () == OP_BUY 
    
    && OrderOpenPrice () >= Oprice + lowdiference 
    
    && OrderOpenPrice () <= Oprice + highdiference )

Is it written without mistake?

I need it to check if there is an order that OrderOpenPrice is in this borders (Oprice + lowdiference =< OrderOpenPrice () <= Oprice + highdiference)

Couse if there is an order than i don't want to open another. I don't use strictly price becouse there is always slippage when the order goes on the market, so I need to use borders like above....

Asking for help :)

Mabe another thinking - easier......

 

Suggest you break down your prb to smaller ones, before you decide "maybe another thinking - easier...."

There really is no point to switch from one way to another, if you cant answer in definitive fashion, such as these questions below:


Smaller 1: what really this suppose to mean, or at least you intend, when need it to check if there is an order

is it an order place: via

the same EA only ---- (EA) or

via all means (same EA+manually+other EAs, etc) ----- (EX)

Smaller 2: How many orders at any given time, either via EA or EX or both above, do you want?

Smaller 3: Suppose if there is no such order, for both cases (EA, EX), then ordersend 1,2, how many?? Then what?

Smaller 4: Suppose order exist, you want to know its open price. and then what?

 

This is ea to work only automaticly at the end.

If there is any order than it will be only one order.

maybe another thinking - easier.... // I've say that becouse mabe you have any other ideas how to select the order that is higher than Oprice + lowdiference and lower than Oprice + Highdiference.

I don't really know even my idea is working becouse my ea for now is only sending two first orders at the begining of code.

Can you tell me if this is all write with logic.

        {
        if (OrderSelect(i, SELECT_BY_POS)

        && OrderSymbol () == Symbol()

        && OrderType () == OP_BUY 
    
        && OrderOpenPrice () >= Oprice + lowdiference 
    
        && OrderOpenPrice () <= Oprice + highdiference )
        {
 
BorysekPL:

This is ea to work only automaticly at the end.

If there is any order than it will be only one order.

maybe another thinking - easier.... // I've say that becouse mabe you have any other ideas how to select the order that is higher than Oprice + lowdiference and lower than Oprice + Highdiference.

I don't really know even my idea is working becouse my ea for now is only sending two first orders at the begining of code.

Can you tell me if this is all write with logic.

its fine by computational sense since all conditions are exactly boolean in nature.

but if i want to be honest and perchance you don't mind me being so, this piece of sub-logic, to me:

OrderOpenPrice () >= Oprice + lowdiference && OrderOpenPrice () <= Oprice + highdiference ) <------ is mathematically nonsense (?)

proof (?): say,
OrderOpenPrice=x, Oprice =y,
lowdiff= L, highdiff= H.

oPrice = OrderOpenPrice,
so, x=y. hence,
x>=y+L <--> x>=x+L <-->.(means true if and only if) <---> L=0. Since L>0 (for some n*Point as you have it from the beginning), this logic is 
mathematically unsound, albeit returning false and perfectly OK in "computational soundness".  Same reasoning applies for H.

Besides "computational soundness" and even before coding them, mathematical soundness is the more important criteria. 

 
diostar:

its fine by computational sense since all conditions are exactly boolean in nature.

but if i want to be honest and perchance you don't mind me being so, this piece of sub-logic, to me:


No, I think that you are more educated than me so I don't want to looks as a person who knows better. Just looking for help and solution of problem:)

so not:

OrderOpenPrice () >= Oprice + lowdiference && OrderOpenPrice () <= Oprice + highdiference ) <------ is mathematically nonsense (?)

but:

Bid () >= Oprice + lowdiference && Bid () <= Oprice + highdiference ) <------   this can make sense?

Becouse Oprice is OpenOrderPrice from the last order. Course = Bid:

if (Oprice >=1 &&  course >= Oprice + diference)

Next I want to select the order that could been opened higher firstly than the last order. // just thought that this order had been opened before course break down and the another order was open.

The Oprice is correctly the OrderOpenPrice of this another/last order.

mabe there is my mistake.....

Couse if there is an order that was opened higher but it wasn't last order than how can i find it and select?

I thought that if i ask program to select order that is in the borders of:

OrderOpenPrice () >= Oprice + lowdiference && OrderOpenPrice () <= Oprice + highdiference )

Than it find me the order that is more than Oprice + lowdiference and less than Oprice + High diference.

Now when it's going bad I know that something is going wrong.

Please tell me if you know solution of this problem.

You have been absolutly wright only if EA always selecting last order and than checking if the another conditions are ok, but if it is looking for order that is owrite with all conditions that I give him, than it should select only this one that I want from the all orders on the market....

I don't really know the method of how EA is selecting orders so I have this problem:)

Still looking for help:)

 
BorysekPL:


No, I think that you are more educated than me so I don't want to looks as a person who knows better. Just looking for help and solution of problem:)

.....


your last explanations/reasoning, is definitely better than previous. and don't go like that is more educated, just bec. I fill with some explanations, which really cannot be put in any other ways, simpler. If there are and believe me, I would. That makes simpler for me too. So, when I say computational sense and mathematical sense, what im trying to point out (maybe this is better approach) is:

1) the former(computational sense) is like the mug,

2) and the beer is like the math.

im asking you, which should you consider first?

you seem to be heading, "my mug comes first than my beer." which is of course, normal for anyone getting ready to drink, but then, be prepared for an empty mug. Meaning to say, you and your codes could be waiting all day, and not a single drop of beer fills it. And I dont think you're happy stuck with that.

On the other hand, if you had considered the beer first (which kind, which grade, which ctry, %, etc, etc, analogously, the math and logic behind every operations) it is pleasant, taste good, you can fill it into any mug (with no holes, of course, analogously the way you code) for what you care, still work fine. Important thing here, there is good beer to fill the mug.


hope this clear...

Reason: