Commit e7ed270d authored by denis's avatar denis

fixed bug in atr based sl calculation, added example query to documentation

parent b683e788
.kdev4
otrasys
OTraSys.kdev4
temp
......@@ -544,8 +544,18 @@ CREATE TABLE `stoploss_daily` (
```
#### Example queries
```
tbd
Query database for a specific symbols quote date, but do so only where
there are stop loss records. This comes in handy if you want to plot your
quotes and the corresponding stop losses at that time.
```
SELECT * FROM
(SELECT quotes_daily.date,quotes_daily.symbol,quotes_daily.open,
quotes_daily.high, quotes_daily.low, quotes_daily.close, stoploss_record.sl FROM
quotes_daily
LEFT JOIN
stoploss_record ON (stoploss_record.date = quotes_daily.date AND stoploss_record.symbol='DAIML')
where quotes_daily.symbol="DAIML" GROUP BY quotes_daily.date ORDER BY quotes_daily.date DESC)
SUB ORDER BY date;
```
-------------------------------------------------------------------------------
......
......@@ -542,7 +542,8 @@ int update_indicators(class_market* the_market)
// ATR/TR is needed by chandelier stops, TR also by ADX indicator
if(biseqcstr(parms.SL_TYPE, "chandelier") ||
biseqcstr(parms.SIGNAL_REGIME_FILTER, "ADX"))
biseqcstr(parms.SIGNAL_REGIME_FILTER, "ADX") ||
biseqcstr(parms.SL_TYPE, "atr"))
{
the_market->addNewIndicator(the_market, "HH_atr_period", parms.INDI_DAYS_TO_UPDATE, "lowest low for INDI_ADX_PERIOD days", "indicators_daily");
the_market->addNewIndicator(the_market, "LL_atr_period", parms.INDI_DAYS_TO_UPDATE, "lowest low INDI_ADX_PERIOD days", "indicators_daily");
......
......@@ -87,6 +87,7 @@ float new_stop_loss(class_market* the_market, unsigned int quote_idx, signal_typ
{
float atr = 0;
int atr_idx = quote_idx - parms.SL_ATR_PERIOD; //TODO: make a sanity check for proper configuration
atr = the_market->Ind[the_market->getIndicatorPos(the_market, "ATR")]->QUOTEVEC[atr_idx];
check(atr_idx >= 0, "not enough quotes (%i) for market %s (vs. %i SL_ATR_PERIOD), check data/%s", error_nr_quotes, the_market->Ind[the_market->IndPos.close]->NR_ELEMENTS, bdata(*the_market->symbol), parms.SL_ATR_PERIOD, bdata(*the_market->csvfile));
new_sl = atr_stop(the_quote, atr, parms.SL_ATR_FACTOR, the_type);
......@@ -205,7 +206,7 @@ float atr_stop(float price, float atr, float atr_factor, signal_type type)
stoploss = 0;
break;
}
return stoploss;
}
......
......@@ -9,6 +9,6 @@ SELECT * FROM
INNER JOIN
indicators_daily indicators ON
(indicators.date = quotes.date AND
quotes.symbol='DJI')
quotes.symbol='DAIML')
GROUP BY quotes.date ORDER BY quotes.date DESC limit 200)
SUB ORDER BY date;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment