are the orders sorted ??

4 replies

krzysiaczek99

Subscriber, bbp_participant, community, 57 replies.

Visit profile

7 years ago #116287

Hi,

 

I’m designing plugin which plots number of open lots and I found out that the orders from SQOrderList are not sorted

 

According to some info from another plugins they suppose to be sorted

/**
	 * Function receives list of all orders sorted by open time and it could manipulate
	 * the list and remove any order that matches certain filter from the list.
	 *
	 * Order structure is available in the documentation here:
	 * http://www.strategyquant.com/doc/api/com/strategyquant/lib/results/SQOrder.html
	 *
	 * @param originalOrders - list of original orders that can be changed. Each order has the order properties specified above
	 */

but my code dedects this

package com.strategyquant.extend.TradeAnalysisPanes;

import org.jfree.chart.JFreeChart;
import com.strategyquant.lib.snippets.TradeAnalysisChartPane;
import com.strategyquant.lib.results.SQData;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.settings.SQConst;
import com.strategyquant.lib.results.SQOrderList;
import com.strategyquant.lib.results.SQOrder;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.charts.common.SQLineChart;
import java.util.Date;

public class MaxNumberOfTrades extends TradeAnalysisChartPane {

	public MaxNumberOfTrades() {
		this.name = "MaxNumberOfTrades";
	}
	
   @Override
	public JFreeChart drawChart(SQResultsGroup strategyResult, SQData data) {
		SQLineChart chart = new SQLineChart();
      chart.xLegend = L.t("Trades");
      chart.yLegend = L.t("Lots");
           
      if(strategyResult==null) {
         return chart.render();
      }

     SQOrderList orderList = filterOrders(strategyResult, data);


     int lots = 0;
     long exittime = orderList.get(0).CloseTime;

     Date d = new Date(exittime);
     Date top = new Date(orderList.get(0).OpenTime);
     Date bottom = new Date(orderList.get(orderList.size()-1).OpenTime);
     
     System.out.println("Closetime "+d);
     System.out.println("Top "+top);
     System.out.println("Bottom "+bottom);


     for (int i = 0; i < orderList.size(); i++) {
      
       //System.out.println(orderList.get(i).OpenTime);
       //System.out.println(order.OpenTime);
       //System.out.println(order.CloseTime);
      
      if ( orderList.get(i).OpenTime <= exittime ) // exit time
      { lots++; }
      else
      { 
         lots = 0;
         exittime = orderList.get(i).CloseTime;
      }
           
      chart.add("", i+1, lots);
       
      }

		return chart.render();
	}
}

Closetime Mon Apr 04 10:12:00 GMT 2016
Top Thu Mar 31 23:08:00 GMT 2016
Bottom Fri Apr 01 00:01:00 GMT 2016

 

so orders are just upside down in comparison to trade file. In trade file there are orders with OpenPrice from 28.03 and 30.03 so 28.03 suppose to be at the bottom not 31.03

I’m enclosing trade file this I use for this test.

 

Can you give an example how to sort them ?

 

Krzysztof

 

0

krzysiaczek99

Subscriber, bbp_participant, community, 57 replies.

Visit profile

7 years ago #141436

So what is the answer for this  ?? How many measures from QA showing wrong values because of this bug ?? When you are going to fix it ??? Hard to believe…this product is so many years around and still major bugs in….

 

Krzysztof

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #141501

Hello,

 

you are referring to a help comment from totally different category of snippets, it is not said that TradeAnalysis snipet uses ordered trades in any particular order, because order of trades does not influence most of these statistics.

 

But you you easily sort the orders by using command:

Collections.sort(orderList, new OrderComparatorByCloseTime());

 

you also have to add two imports to do that:

import java.util.Collections;
import com.strategyquant.lib.comparators.OrderComparatorByCloseTime;
 
You can altervatively sort orders by open time using OrderComparatorByOpenTime() or by ticket using OrderComparatorByOrder()

Mark
StrategyQuant architect

0

krzysiaczek99

Subscriber, bbp_participant, community, 57 replies.

Visit profile

7 years ago #141504

Hi,

 

Thanks for the info. So after sorting trades will be in ascending or descending order ?? If descending how to flip this list upside down ??

will  Collections.reverse(orderList) work ??

 

Krzysztof

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #141516

it is in natural order. Collections.reverse() should work.

Mark
StrategyQuant architect

0

Viewing 4 replies - 1 through 4 (of 4 total)