[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 37

 
skyjet:

Thank you very much for your answer! But still, how to describe the future bar following Ask[0],Bid[0]?

As soon as this future bar appears it will become zero. And the bar that is now [0] will be [1].


Ask and Bid are NOT arrays, there is only one current value, all past ones are forgotten

 

Please help me to understand the calculation of the deposit
because my estimated deposit coincides exactly with the terminal
only when all orders are fully locked
. When I add one more order to the system of orders - the result of the deposit
terminal always differs from my estimated deposit very slightly
but I can never get to be a bullet in a bullet!
Here is a very short example:

The account has 4 orders of 10.00 lots each, two of them bikes
and two sells. It is clear that the account is in balance and all the orders are locked
We calculate the standard deposit for each order, divide it by 4 and everything is tiptoe
The terminal knocks exactly.

We put one more byke at 1.00 lot at 1.4059
We calculate the deposit. It is clear that for it we have to pay the standard deposit
since all existing orders are in the box.
For a leverage of 1:100 we have the pledge for the new bike

ZALBuy = 140.59*1.00 = 140.59

Therefore, the former deposit should be increased by this amount,
Add the former deposit and the deposit for our 1.00 byte

ZAL=ZALold + ZALBuy = 1407.23 + 140.59 = 1547.82

After the setting of the bye in the terminal the deposit turned out to be 1547.91
This would be acceptable if I had put the bye 9 points higher than
at the exchange rate 1.4068 For if we calculate the real increase of the deposit
as the difference of the deposit before and after, we get exactly the standard deposit
for 1.00 lot at the rate 1.4068

1547.91 - 1407.23 = 140.6801

Changed terminal version, alas, did not help!

-----------------------------------------------

Please forgive me for taking your time, but these
constant small discrepancies are very annoying for me
as my machine counts different options,
and the deposit as balance and profit is used to calculate
all account parameters after certain actions before their implementation
. So accuracy is very desirable here.
Maybe I do not understand something, but I searched through documentation
and could not find the reason for this discrepancy.
I would be very grateful for your help!


Regards MADZX
 
keep87:


You can forget about this setting. Re-quote occurs if the canteen wants to take your money, they don't care what the gap is, they will do it anyway.) This is the reality of algotrading most of the scam companies who call themselves "the best broker XXXXX" (XXXXXX - insert name of a continent or galaxy, whatever)

Change or not change the setting, everything stays the same.


Absolutely right! I've seen it too !
 
skyjet:
Hello ! Can you give me a description of a real bar +1. For example I need the price of the next bar, not the present one.

As far as I understand you are trying to get information from the machine from the future
If you find a way - share, I would be grateful :)
 
Kobalerro:
Greetings all. I am new to programming myself, so please solve the problem.

It is necessary that multiple EAs on the same account, open a limited number of orders.

For example: 10 EAs but can only open 5 orders, but no more than one per currency pair.

This has been implemented as follows, but it does not work that way.

extern int МаксКолОрдеров   = 5;

//+------------------------------------------------------------------+

int ПодсчетОткрОрдеров() {
  int k=OrdersTotal();
   if (Символ=="0") Символ=Symbol();
    for (int i=МаксКолОрдеров; i<k; i++) {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Символ || Символ=="") {
       if (МагикНомер<0 || OrderMagicNumber()==МагикНомер) {
      if (OrderMagicNumber()<1) return(True);
     }
    }
   }
  }
 return;

}

//+------------------------------------------------------------------+
int start()
  {
   if(ПодсчетОткрОрдеров()==0)ПровТоргУсловий();
   }


I would implement such a show as follows:
All 10 of your horses are working each on its own schedule, as if in adjacent rooms
and therefore none of them knows what the neighbour doing behind the wall - this is the main problem
for your idea!
Therefore, I would instruct each EA to write their actions in a disk file
which will be available to all horses, because it is in the directory of the terminal .
If any of them has a burning desire to make something in their window
should first analyze this file and check the possibility of implementing
wish !
in respect to your scenario you need to add in the file the number of orders
and currency pairs on which they are open
. For example:
EURUSD 1
GBPUSD 1
EURGBP 0

Here we see that we cannot open trades onEURUSD andGBPUSD because the script doesn't allow
to have more than one order per pair.
It's clear that there will be as many lines as there are pairs at work.
With this solution all your horses will always be aware of what is going on at the moment
, and will be able to calculate whether any action is allowed or not at the moment.
When you set an order on any pair, you have to put 1 in the right line
When you close it, replace it with zero
This will definitely work, although a bit complicated for a newbie
. But go ahead, because everyone was there - like a newbie until the time comes!

Have a good hunt!
MADZX

 

I am writing a pullback strategy. I need to place a stop order above (below) the extremum of the corresponding candle. Here is an example:

It is clear that if the close is below the open, it is a bearish candle, and vice versa - a bullish candle. I want to know how to make a condition saying that the previous candle is bullish... ... so-and-so.

Logically, I make a function that will determine the type of candle.

int CandleType()
{
  if(Open[1] > Close[1])
    return(BullCandle);
    
  if{Open[1] < Close[1]}
    return(BearCandle);
    
  return(dodji);
}

Then you should somehow ask if the bar with index 1 is bullish or bearish... ...and do something...

How do I do it?

 
madzx:


I would implement such a show like this:
All 10 of your horses are working each on their own schedule, as if in adjacent rooms
and therefore none of them knows what the neighbour doing behind the wall - this is the main problem
for your idea!
Therefore, I would instruct each EA to write their actions in a disk file
which will be available to all horses, because it is in the directory of the terminal .
If any of them has a burning desire to make something in their window
should first analyze this file and check the possibility of implementing
wish !
in respect to your scenario you need to add in the file the number of orders
and currency pairs on which they are open
. For example:
EURUSD 1
GBPUSD 1
EURGBP 0

Here we see that we cannot open trades onEURUSD andGBPUSD because the script does not allow
to have more than one order per pair.
It is clear that there will be as many lines as there are pairs in operation.
With this solution all your horses will always be aware of what is going on at the moment
, and will be able to calculate whether any action is allowed or not at the moment.
When you set an order on any pair, you have to put 1 in the right line
When you close it, replace it with zero
This will definitely work, although a bit complicated for a newbie
. But go ahead, because everyone was there - like a newbie until the time comes!

Have a good hunt!
MADZX

Thanks for the tip, but it is a bit too complicated. And then in your version it turns out all work, and it takes 10 to check the condition for entry,

But they open only the first five that have made it in time and then, when one of them closes, the first one that matches the conditions opens again,

not limited to EURUSD 1 , GBPUSD 1 , EURGBP 0.

I think there should be a simpler solution. It should be similar to counting the total number of orders with a limitation condition by a given parameter.

And the limitation can be set either by a symbol or a magic number not more than one.

Although your version would probably work too but I cannot decide how to implement it in code.

 
hoz:

I have a strange thing going on here. Here is the function of opening orders:

here's the error:

if(SL < g_stopLevel)
    SL = g_stopLevel*pt;

if stop level = 5 then you're trying to put a stop loss at 0.00005.

The second error is that you do not check where you are placing the order. If the candlestick closed at or near its high low, you will get error 130. As you can see in the picture, the server opened a sell order instead of a sellstop because you tried to open a sellstop order at a price higher or equal to the current price.

Learn to use the print. Just put Print(); in the right place, put the required variables in brackets and separate them with this: ," ", like this: Print(Price," ",SL); and during testing at the moment of opening an order in the tab "Experts" you will see what these variables are equal to, and you will be able to understand what is wrong.

The log will also show what the EA is trying to do, where to set a Stop Loss and Take Profit. You will see everything you need there.

Logically, I make a function that will detect the type of candle.

Let's work inside the function start.

First, we create a variable in which we will write the direction of the previous candle.

int Candle=-1;

We will fill it with some values, one of which will denote a bullish, another - bearish. If -1, it is nothing (it hasn't been determined or it has no direction close=open).

Value I propose to use by analogy with a trade order 0 - buy, 1 - sell;

then we need to write:

if(Close[1]>Open[1]) Candle=0; else
if(Close[1]<Open[1] Candle=1;

Now we have a direction defined and we can use it directly in the OrderSend( string symbol, int cmd, ...other stuff...) function;

if(Candle!=-1) OrderSend( Symbol(),Candle, ...other stuff...);

or following your analogy:

if(Candle==0) OpenBuy();
if(Candle==1) OpenSell();

 
Kobalerro:

Thanks for the tip, but it is a bit too complicated. And then it turns out that all of them work in your variant and it takes 10 to check entry condition,

and they open only five that have made it in time first and then when one of them closes, the first one that matches the conditions opens again,

not limited to EURUSD 1 , GBPUSD 1 , EURGBP 0.

I think there should be a simpler solution. It should be like counting the total number of orders with a limitation condition by a given parameter.

And we need to limit this number either by a symbol or by a magic number, or by no more than one.

Although, perhaps, your option will also work, but how to implement it in the code, I can not think.


Or maybe like this :

if(NumberOfPositions("EURUSD")==0 && NumberOfPositions()<10)
And here the function
 
keep87:

there's an error here:

if stop level = 5 then you are trying to put a stop loss at 0.00005.

The second error is that you do not check where you are placing the order. If the candlestick closed at or near its high low, you will get error 130. As you can see in the picture, the server opened a sell order instead of a sellstop, because you tried to open a sellstop at a price higher or equal to the current price.

Learn to use the print. Just put Print(); in the right place, put the required variables in brackets and separate them with this: ," ", like this: Print(Price," ",SL); and during testing at the moment of opening an order in the tab "Experts" you will see what these variables are equal to, and you will be able to understand what is wrong.

The log will also show what the EA is trying to do, where to set a Stop Loss and Take Profit. It will show everything that is needed.

I use it that way from time to time. Look, now the functions look like this:

//+-------------------------------------------------------------------------------------+
//| Открытие длинной позиции                                                            |
//+-------------------------------------------------------------------------------------+
bool OpenBuy()
{
  int ticket = -1;
  string myNote = "Сов баянул";
  
  double price = High[1] + i_thresholdFromInput*pt;
  Print("price = ", price);
  double SL = Low[1] - i_thresholdFromBasedSL*pt ;
  Print("SL = ", SL);

  if(price > Ask)
  {
    ticket = OrderSend(Symbol(),OP_BUYSTOP,0.1,NormalizeDouble(price,Digits),i_slippage,0,0,myNote,i_myMagic,TimeCurrent() + 600,Navy);
  }
  
  if(ticket > 0 && OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES) == true)
    if(!OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(SL,Digits),NormalizeDouble(High[1] + i_tp*pt,Digits),0,Navy))
    return(false);
  
  return(true);
}
//+-------------------------------------------------------------------------------------+
//| Открытие короткой позиции                                                           |
//+-------------------------------------------------------------------------------------+
bool OpenSell()
{
  int ticket = -1;
  string myNote = "Сов шортанул";
  
  double price = Low[1] - i_thresholdFromInput*pt;
  Print("price = ", price);
  double SL = High[1] + i_thresholdFromBasedSL*pt;
  Print("SL = ", SL);
  
  if(price < Bid)
  {
    ticket = OrderSend(Symbol(),OP_SELLSTOP,0.1,NormalizeDouble(price,Digits),i_slippage,0,0,myNote,i_myMagic,TimeCurrent() + 600,Red);
  }
  
  if(ticket > 0 && OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES) == true)
    if(!OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(SL,Digits),NormalizeDouble(Low[1] - i_tp*pt,Digits),0,Red))
    return(false);
    
  return(true);
}

I read in the journal:

2012.12.25 18:20:16     2012.02.13 00:05  5_minites_TS_by_Philippe Nell EURUSD,M5: modify #1 buy stop 0.10 EURUSD at 1.32103 sl: 1.32007 tp: 1.32243 ok
2012.12.25 18:20:16     2012.02.13 00:05  5_minites_TS_by_Philippe Nell EURUSD,M5: open #1 buy stop 0.10 EURUSD at 1.32103 ok
2012.12.25 18:20:16     2012.02.13 00:05  5_minites_TS_by_Philippe Nell EURUSD,M5: SL = 1.3201
2012.12.25 18:20:16     2012.02.13 00:05  5_minites_TS_by_Philippe Nell EURUSD,M5: price = 1.321
2012.12.25 18:20:14     2012.02.13 00:00  5_minites_TS_by_Philippe Nell EURUSD,M5: OrderSend error 130
2012.12.25 18:20:14     2012.02.13 00:00  5_minites_TS_by_Philippe Nell EURUSD,M5: SL = 1.3194
2012.12.25 18:20:14     2012.02.13 00:00  5_minites_TS_by_Philippe Nell EURUSD,M5: price = 1.3204
2012.12.25 18:20:14     5_minites_TS_by_Philippe Nell inputs: i_fastMaPeriod=10; i_slowMaPeriod=21; i_filtrMaPeriod=50; i_trading_TF=5; i_thresholdFromInput=1; i_thresholdFromBasedSL=1; i_slippage=3; i_tp=15; i_myMagic=33330215; 
2012.12.25 18:20:12     5_minites_TS_by_Philippe Nell EURUSD,M5: loaded successfully

So initially from the buy price to the stop was the difference 1.3204 - 1.3194 = 0.001 points

Further 1.3210 - 1.3201 = 0.009 points

And for some reason in the second case, the stop was closer to the entry price, but there was no error! I thought about it and did not understand it.

I corrected the error later in a different way. There are already conditions in the code:

if(price > Ask) && if(price < Bid) respectively for buying and selling. Or was there another variant? Now we have no more errors. But, nevertheless, I'd like to listen to an opinion from a more experienced programmer.

Reason: