stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Desky. TDesk's trading drone.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5545
Page 24 of 50
Author:  SteveHopwood [ Tue Mar 05, 2019 11:03 am ]
Post subject:  Desky. TDesk's trading drone.

c1borg » Tue Mar 05, 2019 8:48 am wrote:I have this repeating error no idea if its a bug.
2019.03.05 09:19:18.332 TDesk Trading Partner EAz XAUUSD,H1: Alert: Sell stop: Lots 0.01: Price 0.6802: Bid 0.6795600000000001: TP 0.0: SL 0.0
2019.03.05 09:19:18.320 TDesk Trading Partner EAz XAUUSD,H1: NZDUSD TDesk Trading Partner EAz OP_SELLSTOP order send failed with error(130): invalid stops
Could be my mistake and im certainly not proficient enough as a coder to spot this yet, however I will attempt to figure it out.

Analysis so far, I have 1 NZDUSD trade active and no pending trades. I am also using the new Rolling Grid feature set to enabled and so I tried to disable that feature but it still happens. Im also using the feature on another demo with no issues. My observation is It seems to be attempting to place the trade above the current one, is that a clue.




Edit......

Ok tracked it down to the setting UseAtrForGrid which I have set to true with the default settings seems to be causing the problem.
  • UseGridTrading=true
    TypeOfGrid=0
    GridSize=3
    DistanceBetweenTradesPips=125
    UseAtrForGrid=true
    GridAtrTimeFrame=1440
    GridAtrPeriod=20
    GridAtrDivisor=5.0
I need to adjust my ATR settings any recommendations?
This shows the value of including error reporting alerts in the code.

The Bid price is a variable of the double type, so it has 8 decimal points. Crapql4 sometimes replaces the final 0 with a 1. See the value of the order price being sent - 0.6795600000000001. That has happened here and so the order generates the invalid stop error.

Desky needs to know the bid, ask and no of decimal points (known as "Digits) for each individual pair so there is a function that reads these at the start of many functions by calling void GetBasics(string symbol). Here it is as it now is in V3 in post 1:

Code: Select all

void GetBasics(string symbol)
{
   //Sets up bid, ask, digits, factor for the passed pair
   digits = (int)MarketInfo(symbol, MODE_DIGITS);
   bid = NormalizeDouble(MarketInfo(symbol, MODE_BID), digits);
   ask = NormalizeDouble(MarketInfo(symbol, MODE_ASK), digits);
   factor = GetPipFactor(symbol);
   longSwap = MarketInfo(symbol, MODE_SWAPLONG);
   shortSwap = MarketInfo(symbol, MODE_SWAPSHORT);
   
      
}//End void GetBasics(string symbol)
You can see how I have replaced the usual Bid, Ask etc with the same names but with lower case. Look at:
bid = NormalizeDouble(MarketInfo(symbol, MODE_BID), digits);

NormalizeDouble forces the variable to hold only the value of the digits after the decimal point, so removing the chance of the eighth having the erroneous 1 added. If you go to the function in your current version, you will see that this is missing. I also had to slightly rearrange the order so that 'digits' is correctly populated.

Copy the code here over the top of the code in 2z. Look a few lines down to the top of bool LookForTradingOpportunities(string symbol, int pairIndex, int type). You will see this code:
GetBasics(symbol);

This ensures that Desky is working with up to date values.

The void OnTimer() event holds the iteration through our list of trading pairs. Find it with a search for:
for (int pairIndex = 0; pairIndex < ArraySize(TDeskSymbols); pairIndex++)

Three lines above this you will see: string symbol = "";

pairIndex is assigned the place in our trade pair list. 'symbol' is assigned the pair symbol such as GBPUSD. These are then passed to every subsequent called function e.g. DoHedging(symbol, pairIndex);

So, if you want to add your own functions define them like this:
void MyFunction((string symbol, int pairIndex)
{
GetBasics(symbol);

Rest of function;

}

Then call it from where ever is appropriate:
MyFunction(symbol, pairIndex);

You pass symbol and pairIndex around whenever you call a new function. pairIndex is not always needed but I have taken lately to passing it around anyhow, so it can be passed from function to function. Suppose you have defined two functions and the second is called from within the first:

void MyFunction((string symbol, int pairIndex)
{
GetBasics(symbol);

double priceToSend = MySecondFunction(symbol, pairIndex);

}

double MySecondFunction((string symbol, int pairIndex)
{
GetBasics(symbol);

double price = bid;
return (price);

}

The void DoHedging(string symbol, int pairIndex) function calls two sub-functions, so have a look to see a real example.

:xm: :rocket:
Author:  c1borg [ Tue Mar 05, 2019 12:52 pm ]
Post subject:  Desky. TDesk's trading drone.

SteveHopwood » Tue Mar 05, 2019 11:03 am wrote: This shows the value of including error reporting alerts in the code.

The Bid price is a variable of the double type, so it has 8 decimal points. Crapql4 sometimes replaces the final 0 with a 1. See the value of the order price being sent - 0.6795600000000001. That has happened here and so the order generates the invalid stop error.

Desky needs to know the bid, ask and no of decimal points (known as "Digits) for each individual pair so there is a function that reads these at the start of many functions by calling void GetBasics(string symbol). Here it is as it now is in V3 in post 1:

Code: Select all

void GetBasics(string symbol)
{
   //Sets up bid, ask, digits, factor for the passed pair
   digits = (int)MarketInfo(symbol, MODE_DIGITS);
   bid = NormalizeDouble(MarketInfo(symbol, MODE_BID), digits);
   ask = NormalizeDouble(MarketInfo(symbol, MODE_ASK), digits);
   factor = GetPipFactor(symbol);
   longSwap = MarketInfo(symbol, MODE_SWAPLONG);
   shortSwap = MarketInfo(symbol, MODE_SWAPSHORT);
   
      
}//End void GetBasics(string symbol)
You can see how I have replaced the usual Bid, Ask etc with the same names but with lower case. Look at:
bid = NormalizeDouble(MarketInfo(symbol, MODE_BID), digits);

NormalizeDouble forces the variable to hold only the value of the digits after the decimal point, so removing the chance of the eighth having the erroneous 1 added. If you go to the function in your current version, you will see that this is missing. I also had to slightly rearrange the order so that 'digits' is correctly populated.

Copy the code here over the top of the code in 2z. Look a few lines down to the top of bool LookForTradingOpportunities(string symbol, int pairIndex, int type). You will see this code:
GetBasics(symbol);

This ensures that Desky is working with up to date values.

The void OnTimer() event holds the iteration through our list of trading pairs. Find it with a search for:
for (int pairIndex = 0; pairIndex < ArraySize(TDeskSymbols); pairIndex++)

Three lines above this you will see: string symbol = "";

pairIndex is assigned the place in our trade pair list. 'symbol' is assigned the pair symbol such as GBPUSD. These are then passed to every subsequent called function e.g. DoHedging(symbol, pairIndex);

So, if you want to add your own functions define them like this:
void MyFunction((string symbol, int pairIndex)
{
GetBasics(symbol);

Rest of function;

}

Then call it from where ever is appropriate:
MyFunction(symbol, pairIndex);

You pass symbol and pairIndex around whenever you call a new function. pairIndex is not always needed but I have taken lately to passing it around anyhow, so it can be passed from function to function. Suppose you have defined two functions and the second is called from within the first:

void MyFunction((string symbol, int pairIndex)
{
GetBasics(symbol);

double priceToSend = MySecondFunction(symbol, pairIndex);

}

double MySecondFunction((string symbol, int pairIndex)
{
GetBasics(symbol);

double price = bid;
return (price);

}

The void DoHedging(string symbol, int pairIndex) function calls two sub-functions, so have a look to see a real example.

:xm: :rocket:
Using the new version ATR set to true and we still get an error. This feature is working on other demos could it be the ATR is too low on NZDUSD?

Day's Range: 0.6790 - 0.6828
2019.03.05 13:48:40.951 TDesk Trading Partner EA3 XAUUSD,H1: NZDUSD TDesk Trading Partner EA3 OP_SELLSTOP order send failed with error(130): invalid stops
2019.03.05 13:48:35.737 TDesk Trading Partner EA3 XAUUSD,H1: Alert: Sell stop: Lots 0.01: Price 0.6802: Bid 0.6792899999999999: TP 0.0: SL 0.0
Author:  SteveHopwood [ Tue Mar 05, 2019 5:02 pm ]
Post subject:  Desky. TDesk's trading drone.

c1borg » Tue Mar 05, 2019 12:52 pm wrote: Using the new version ATR set to true and we still get an error. This feature is working on other demos could it be the ATR is too low on NZDUSD?

Day's Range: 0.6790 - 0.6828
Check you are using the latest version. Or have recompiled if you DIY'd.

:xm: :rocket:
Author:  c1borg [ Tue Mar 05, 2019 7:16 pm ]
Post subject:  Desky. TDesk's trading drone.

SteveHopwood » Tue Mar 05, 2019 5:02 pm wrote:
c1borg » Tue Mar 05, 2019 12:52 pm wrote: Using the new version ATR set to true and we still get an error. This feature is working on other demos could it be the ATR is too low on NZDUSD?

Day's Range: 0.6790 - 0.6828
Check you are using the latest version. Or have recompiled if you DIY'd.

:xm: :rocket:
Ok checked and everything looks right
Capture.PNG
Capture1.png
Author:  SteveHopwood [ Tue Mar 05, 2019 8:04 pm ]
Post subject:  Desky. TDesk's trading drone.

c1borg » Tue Mar 05, 2019 7:16 pm wrote:
SteveHopwood » Tue Mar 05, 2019 5:02 pm wrote:
c1borg » Tue Mar 05, 2019 12:52 pm wrote: Using the new version ATR set to true and we still get an error. This feature is working on other demos could it be the ATR is too low on NZDUSD?

Day's Range: 0.6790 - 0.6828
Check you are using the latest version. Or have recompiled if you DIY'd.

:xm: :rocket:
Ok checked and everything looks right

Then I have no idea what the problem is.

You around, tutank?

:xm: :rocket:
Author:  c1borg [ Tue Mar 05, 2019 8:56 pm ]
Post subject:  Desky. TDesk's trading drone.

SteveHopwood » Tue Mar 05, 2019 8:04 pm wrote: Then I have no idea what the problem is.

You around, tutank?

:xm: :rocket:
I don't think it's a major issue and only seems to arise if the ATR is small :smile:
Author:  tutank [ Wed Mar 06, 2019 3:12 pm ]
Post subject:  Desky. TDesk's trading drone.

2019.03.05 09:19:18.332 TDesk Trading Partner EAz XAUUSD,H1: Alert: Sell stop: Lots 0.01: Price 0.6802: Bid 0.6795600000000001: TP 0.0: SL 0.0
2019.03.05 09:19:18.320 TDesk Trading Partner EAz XAUUSD,H1: NZDUSD TDesk Trading Partner EAz OP_SELLSTOP order send failed with error(130): invalid stops
Have you modified the code, there's something wrong because SELLSTOP price 0.6802 is higher than current BID 0.67956...
Author:  SteveHopwood [ Wed Mar 06, 2019 4:11 pm ]
Post subject:  Desky. TDesk's trading drone.

tutank » Wed Mar 06, 2019 3:12 pm wrote:
2019.03.05 09:19:18.332 TDesk Trading Partner EAz XAUUSD,H1: Alert: Sell stop: Lots 0.01: Price 0.6802: Bid 0.6795600000000001: TP 0.0: SL 0.0
2019.03.05 09:19:18.320 TDesk Trading Partner EAz XAUUSD,H1: NZDUSD TDesk Trading Partner EAz OP_SELLSTOP order send failed with error(130): invalid stops
Have you modified the code, there's something wrong because SELLSTOP price 0.6802 is higher than current BID 0.67956...
No, but I had a look at DoesTradeExist() and found bloops that are not helping matters. There are places in the code where I had not replaced Symbol() with the passed parameter "symbol". This could also explain the total failure of counter-trend trading.

DIYers, go to:
bool DoesTradeExist(int type, double price)

Add string symbol to the list of parameters:
bool DoesTradeExist(int type, double price, string symbol)

Scroll down to:
if (OrderSymbol() != Symbol() ) continue;

Replace it with:
if (OrderSymbol() != symbol) continue;

Re-compiling wii throw up two errors. Double click them to go to them. They will both be:
if (DoesTradeExist(type, price))

They both need "symbol" adding:
if (DoesTradeExist(type, price, symbol))

Then go to
bool HaveEnoughCandlesReversed(string direction) and repeat the process so that the function has the added parameter:
bool HaveEnoughCandlesReversed(string direction, string symbol)

Scroll down to:
double copen = iOpen(Symbol(), CtsTimeFrame, cc);

Change it to:
double copen = iOpen(symbol, CtsTimeFrame, cc);
Do the same on the next line.

Re-compile and follow the serious error messages to the offending lines and add, ", symbol)" as in this line:
if (HaveEnoughCandlesReversed(down, symbol) )

Don't be tempted to do a global search and replace - there are places in the code where Symbol() is needed.

:xm: :rocket:
Author:  kwchau [ Fri Mar 08, 2019 2:17 pm ]
Post subject:  Desky. TDesk's trading drone.

I'm testing Desky 2z with swap filter all set to true, but notice that trades with negative swap are still being taken.
I have turned off most setting like recovery, hedging etc except rolling grid and offsetting.

Not sure how this happens. I have not test this swap functions in previous version, so I am not sure this is carried forward problem.

Anyone observes the same thing ? Any help will be highly appreciated.

Cheers,
kwchau
Author:  SteveHopwood [ Fri Mar 08, 2019 3:30 pm ]
Post subject:  Desky. TDesk's trading drone.

kwchau » Fri Mar 08, 2019 2:17 pm wrote:I'm testing Desky 2z with swap filter all set to true, but notice that trades with negative swap are still being taken.
I have turned off most setting like recovery, hedging etc except rolling grid and offsetting.

Not sure how this happens. I have not test this swap functions in previous version, so I am not sure this is carried forward problem.

Anyone observes the same thing ? Any help will be highly appreciated.

Cheers,
kwchau
This is nothing that you are doing wrong.

The code is legacy code that does not work here. I will fix it.

:xm: :rocket:
All times are UTC Page 24 of 50