Commit 605a2131 authored by denis's avatar denis

finished SL dump into database

parent 1b5e7a5f
......@@ -355,37 +355,30 @@ int execution_manager(class_accounts *the_account, class_market_list *market_lis
const unsigned int tradingdays = the_portfolio->elements[i]->trading_days + 1;
const float new_sl = new_stop_loss(market_list->markets[market_idx], quote_idx, the_portfolio->elements[i]->type);
float new_sl = new_stop_loss(market_list->markets[market_idx], quote_idx, the_portfolio->elements[i]->type);
// update the SL according to the SL_ADJUST setting
// catch some exceptions when SL should not be updated
if(biseqcstr(parms.SL_ADJUST, "fixed"))
{
the_portfolio->elements[i]->update(the_portfolio->elements[i],
the_portfolio->elements[i]->stoploss, false, tradingdays,
market_list->markets[market_idx], quote_idx, the_account->getCash(the_account));
}
else if(biseqcstr(parms.SL_ADJUST, "updown"))
{
the_portfolio->elements[i]->update(the_portfolio->elements[i],
new_sl, false, tradingdays,
market_list->markets[market_idx], quote_idx, the_account->getCash(the_account));
new_sl = the_portfolio->elements[i]->stoploss;
}
else if(biseqcstr(parms.SL_ADJUST, "trailing"))
{
if(new_sl_needed(new_sl, the_portfolio->elements[i]->stoploss, the_portfolio->elements[i]->type))
the_portfolio->elements[i]->update(the_portfolio->elements[i],
new_sl, false, tradingdays,
market_list->markets[market_idx], quote_idx,
the_account->getCash(the_account));
else
the_portfolio->elements[i]->update(the_portfolio->elements[i],
the_portfolio->elements[i]->stoploss, false, tradingdays,
market_list->markets[market_idx], quote_idx,
the_account->getCash(the_account));
if(!new_sl_needed(new_sl, the_portfolio->elements[i]->stoploss, the_portfolio->elements[i]->type))
new_sl = the_portfolio->elements[i]->stoploss;
}
// update SL records
// update the SL in portfolio element
the_portfolio->elements[i]->update(the_portfolio->elements[i],
new_sl, false, tradingdays,
market_list->markets[market_idx], quote_idx, the_account->getCash(the_account));
// update SL records
unsigned int sl_idx = the_portfolio->elements[i]->getSL_list_idx(the_portfolio->elements[i]);
sl_list->SL[sl_idx]->QuoteObj->appendQuoteTupel(sl_list->SL[sl_idx]->QuoteObj,
&market_list->markets[market_idx]->Ind[ind_index]->QuoteObj->datevec[quote_idx],
market_list->markets[market_idx]->Ind[ind_index]->QuoteObj->daynrvec[quote_idx],
new_sl);
} // update portfolio entries loop
......@@ -633,14 +626,13 @@ int execution_manager(class_accounts *the_account, class_market_list *market_lis
// set Stop Loss
the_portfolio->elements[element_idx]->stoploss = stoploss;
// create SL record
// create SL record and add latest stoploss
sl_list->addNewSL(sl_list, bdata(*market_list->markets[marketPos]->symbol), 0,
the_portfolio->elements[element_idx]->Buyquote_account->nr_digits,
bdata(the_portfolio->elements[element_idx]->Buyquote_account->datevec[0]), bdata(parms.SL_TYPE));
unsigned int sl_idx = sl_list->nr_records-1;
sl_list->SL[sl_idx]->QuoteObj->appendQuoteRecords(sl_list->SL[sl_idx]->QuoteObj, 1);
unsigned int tmp_idx = sl_list->SL[sl_idx]->QuoteObj->nr_elements - 1;
sl_list->SL[sl_idx]->QuoteObj->setQuoteTupel(sl_list->SL[sl_idx]->QuoteObj,0, sl_list->SL[sl_idx]->buydate, current_day, stoploss);
// calculate fee
......@@ -717,11 +709,8 @@ int execution_manager(class_accounts *the_account, class_market_list *market_lis
performance_idx = performance_idx + 1;
} // end of loop through execution period
sl_list->printTable(sl_list);
for(int i = 0; i<sl_list->nr_records; i++)
sl_list->SL[i]->printTable(sl_list->SL[i]);
// dump al SL data to db
sl_list->saveToDB(sl_list);
// cleanup
......
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