open every day week etc than close

 
extern double BaseLot = 0.1;
extern int StopLoss = 50;
extern int TakeProfit = 50;
extern double MagicBUY = 12345;
extern double MagicSELL = 54321;
double ManualMultiply=1;

int Every_day_open = -1; //
int Every_day_close = -1; //???????





int start()
{

   
    
    every_day_open();
    every_day_close();
    
}

void every_day_open()
{
    if (DayOfWeek() != Every_day_open)
    {
        Every_day_open = DayOfWeek();
        Fun_Open_Buy();
        Fun_Open_Sell();
        
    }
}

void Fun_Open_Buy()
{
    double MAG_BUY = MagicBUY;
    
    double S_L = Ask - StopLoss*ManualMultiply*Point;
    double T_P = Ask + TakeProfit*ManualMultiply*Point;
    if (StopLoss == 0) S_L = 0;
    if (TakeProfit == 0) T_P = 0;
    
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BaseLot, Ask, 4, 0, 0, "buy every", MAG_BUY, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BaseLot, Ask, 4, S_L, T_P, "buy every", MAG_BUY, 0, Blue);
    
}

void Fun_Open_Sell()
{
    double MAG_SELL = MagicSELL;

    double S_L = Bid + StopLoss*ManualMultiply*Point;
    double T_P = Bid - TakeProfit*ManualMultiply*Point;
    if (StopLoss == 0) S_L = 0;
    if (TakeProfit == 0) T_P = 0;
    
    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, BaseLot, Bid, 4, 0, 0, "sell every", MAG_SELL, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, BaseLot, Bid, 4, S_L, T_P, "sell every", MAG_SELL, 0, Red);
 
    
}

void every_day_close()
{
    if (DayOfWeek() != Every_day_close)
    {
        Every_day_close = DayOfWeek();
        Close_buy_day_after();
        Close_sell_day_after();
        
    }
}


void Close_sell_day_after()
...

void Close_buy_day_after()

Hi ALL, i have a little problem with my simple ea and i cant get around.... basicly it open sell and buy trade every day, this bit is working however for obvious reason it close trades second after opening... what is the trick in order to delay close function for a day like in this ea or any other fixed amount of day weeks.... of course i could just buy sell, and next day check if any opened trades exist and close them if, but for some reason i need it proposed way... if possible...

Similarly... i had an "ahaaaa" moment the other day in regards of how to trade every 1h, every day.... but AM totally stupid how to get it done in a similar way on the let say weekly or monthly basis.


all suggestions welcome... Thank you.

 

Look at the open trade and determine the time it was opened, then check the current time, subtract one from the other, if the result is greater than the time period you want the order open for close the order.

A question for you, what is this meant to accomplish ?

    if (true)
    ticket = OrderSend(Symbol(), OP_BUY, BaseLot, Ask, 4, 0, 0, "buy every", MAG_BUY, 0, Blue);
    else
    ticket = OrderSend(Symbol(), OP_BUY, BaseLot, Ask, 4, S_L, T_P, "buy every", MAG_BUY, 0, Blue);

true is always true . . what else could it ever be ?

 
NAT_SIE:

opening... what is the trick in order to delay close function for a day

Similarly... i had an "ahaaaa" moment the other day in regards of how to trade every 1h, every day.... but AM totally stupid how to get it done in a similar way on the let say weekly or monthly basis.

  1.     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.
            if (TimeCurrent() - OrderOpenTime() > 24*60*60){ // Order older than 24 hours.
           // or
           // if (Time[0] > OrderOpenTime()){ // Order older than one bar.

  2. Change time frames on the chart.
 
WHRoeder:

  1. Change time frames on the chart.


1. TY.

2. true... and difficult to back test.

also..... whats ur rate if hired???

 
RaptorUK:

Look at the open trade and determine the time it was opened, then check the current time, subtract one from the other, if the result is greater than the time period you want the order open for close the order.

A question for you, what is this meant to accomplish ?

true is always true . . what else could it ever be ?


answer urself... compile it without it:)
 
NAT_SIE:

answer urself... compile it without it:)

It's your code, and you are asking for help with it . . . my point was . . . what is the point of code that is never executed ?

    int ticket = -1;
    if (true)
    ticket = OrderSend(Symbol(), OP_SELL, BaseLot, Bid, 4, 0, 0, "sell every", MAG_SELL, 0, Red);
    else
    ticket = OrderSend(Symbol(), OP_SELL, BaseLot, Bid, 4, S_L, T_P, "sell every", MAG_SELL, 0, Red);

does the same as . . .

    int ticket = -1;
    
    ticket = OrderSend(Symbol(), OP_SELL, BaseLot, Bid, 4, 0, 0, "sell every", MAG_SELL, 0, Red);
    
 
RaptorUK:

It's your code, and you are asking for help with it . . . my point was . . . what is the point of code that is never executed ?

does the same as . . .


i see, i am sorry, there is also a function dealing with stp/ecn.... /not included/ to cover both scenarios. its the way i try to code.... through functions as much as possible for simplicity and flexibility.
Reason: