Buy stop Sell stop Grid advisor as a class - page 2

 

I am adding functionality little by little. When starting, if there are no positions and no pending orders, pending stop orders are placed. The version description is attached to the class file:

//+------------------------------------------------------------------+
//| 1.001:                                                           |
//|   when starting, sets Buy stop and sell stop                     |
//+------------------------------------------------------------------+

ds

 

Interesting - the CBuyStopSellStopGrid::RefreshRates(void) function checks for zero asc-bid values.

Is it really a possible situation?

In general - no more remarks, the code is quite transparent and clear.

 
George Merts:

Interesting - the CBuyStopSellStopGrid::RefreshRates(void) function checks for zero asc-bid values.

Is this situation really possible?

In general, there are no other remarks, the code is quite transparent and clear.


Yes, this is life and anything is possible here. In general, check for zero values entered because of the tester (it was about a year ago: when starting the first t=few ticks the tester gave zeros).

I am adding functionality little by little. In OnTradeTransaction, if there is a position ("DEAL_ENTRY_IN") we remove pending orders and set two stop pending orders anew:

//+------------------------------------------------------------------+
//| 1.001:                                                           |
//|   when starting, sets Buy stop and sell stop                     |
//| 1.002:                                                           |
//|   OnTradeTransaction: if DEAL_ENTRY_IN delete all pending orders,|
//|   and, sets Buy stop and sell stop                               |
//+------------------------------------------------------------------+

BuyStopSellStopGrid 1.002

So far we have such shortcomings:

  1. on every tick, the amount of positions and pending orders is checked
  2. No control of trade operations (pending order placing) - the Expert Advisor does not handle situations if the pending order has not been placed
  3. A set of positions without positions - this situation is not handled, i.e. if we have, say, closed a Buy position, and then a Sell position opened...
 
Vladimir Karputov:

Yes, this is life and anything is possible. In general, the check for zero values was introduced because of the tester (there was a case about a year ago: when starting the first t=few ticks, the tester gave zeros).

I am adding functionality little by little. In OnTradeTransaction, if there is a position ("DEAL_ENTRY_IN") we remove pending orders and set two new stop pending orders:


So far we have such shortcomings:

  1. on every tick, the amount of positions and pending orders is checked
  2. No control of trade operations (pending order placing) - the Expert Advisor does not handle situations if the pending order has not been placed
  3. A set of positions without positions - for example, the situation is not handled, when, say, we opened a Buy position, and then a Sell position opened...

The algorithm shown on the screenshot will not work. To make the algorithm work, you have to do the following:

When a buy signal is received, a grid of BUY STOP orders is placed above the high of the first candle. Below the close price, a SELL STOP order is placed. Orders should be closed not due to profit or loss, but due to another signal. With more or less sane signals, this system will always work.

This is just a variant; you can do everything in a different way.

 
Ibragim Dzhanaev:

If the signals are more or less sane, such a system will always work.

It would be better to write "if you buy at the lows and sell at the highs, you will always be in profit".

Who argues? The problem is to find "reasonable signals".

 

Version 1.003:

//+------------------------------------------------------------------+
//| 1.001:                                                           |
//|   when starting, sets Buy stop and sell stop                     |
//| 1.002:                                                           |
//|   OnTradeTransaction: if DEAL_ENTRY_IN delete all pending orders,|
//|   and, sets Buy stop and sell stop                               |
//| 1.003:                                                           |
//|   OnTradeTransaction: DEAL_ENTRY_IN                              |
//|      DEAL_TYPE_BUY => ClosePositions(POSITION_TYPE_SELL)         |
//|      DEAL_TYPE_SELL => ClosePositions(POSITION_TYPE_BUY)         |
//|   PlacesXXXX:                                                    |
//|      "RefreshRates()" is now inside the "PlacesXXXX"             |
//|   OnTradeTransaction:                                            |
//|      a "while" loop for "PlacesXXXX"                             |
//+------------------------------------------------------------------+

  • now closes ALL opposing positions when a position is opened.
  • current price acquisition has been moved inside the PlacesBuy and PlacesSell functions to protect against gaps and slippages.
  • InOnTradeTransaction pending orders are placed in a while loop - so to say, we are beating the server to the punch :) - It is not the best solution but it will stay for now.

Actually, now we can think:

  1. What is the best way to increase positions (lot volume calculation)?
  2. What to do with opposing positions...

 
George Merts:

A better way would be to write "if you buy at the lows and sell at the highs, you will always be in profit".

Who argues? The problem is to find "reasonable signals".


The simplest and most obvious option.


 
Can I join you?
 

Or so it goes.


 
Artiom Morochin:
Can I join you?

Done. Connect the Warehouse, update project files from the Warehouse.

Reason: